7.3. Writing, Compiling, and Deploying Code

This section of the document does not explain how to write code; rather, it will show where to put classes, stylesheets, JSPs, and other files you create, and the ant commands used to compile and deploy them.

7.3.1. Placing Files

In /var/ccm-devel/dev/username/project-name, there is a subdirectory also called project-name that looks roughly like the following:

-r--r--r--    1 auser   ccm-deve      605 Jul  3 09:13 application.xml
drwxr-xr-x    8 auser   ccm-deve     4096 Jul  8 14:24 doc
drwxrwxr-x    3 auser   ccm-deve     4096 Jul  8 14:24 etc
drwxr-xr-x    3 auser   ccm-deve     4096 Jul  8 14:27 pdl
drwxr-xr-x    3 auser   ccm-deve     4096 Jul  8 14:27 sql
drwxrwxr-x    3 auser   ccm-deve     4096 Jul  8 14:32 src
drwxr-xr-x    5 auser   ccm-deve     4096 Jul  8 14:32 test
drwxr-xr-x    8 auser   ccm-deve     4096 Jul  8 14:34 web

This directory is organized as follows:

When writing code using this structure, you may import classes and pdl "models" from the prebuilt projects or applications you referenced in your project.xml file, above. Note that the structure also gives you complete freedom to overwrite code in precompiled packages or add code to precompiled packages, simply by adding a Java class in the appropriate location under src. Also note that overwriting the precompiled Java code is generally not recommended, since it will make upgrading to a new precompiled project much more difficult.

To add a Java class to your project, place it in a directory under src that mirrors its package hierarchy, following standard Java practice. For example, the com.arsdigita.kernel.ACSObject class will go in src/com/arsdigita/kernel/. To add a PDL file to your product, follow the same pattern. For SQL files, add a database-name directory under sql for each database you want your application to run on (currently "oracle-se" and "postgres" are the only options). Then put the SQL create and drop scripts for each package in a package directory under each database name. For web/, see the deployed webapp for file placement, since everything under that directory is copied directly to the webapp root.

7.3.2. Compiling Code

To test the code you have written, type the ant build command while inside of your main development directory. Ant will attempt to compile your code, and will tell you if it succeeds or where it encounters problems.

Since JSPs and XSL stylesheets are processed at runtime, the "build" step has no effect on them. If you are in active development on a JSP or an XSL stylesheet, it may be more efficient to work directly in the webapp root, since a page reload will show your changes instantly. If you follow this practice, however, make sure to keep careful track of the files you have modified and transfer them to the development area when you are done (where they can be put under source control).

7.3.3. Deploying Code

Once your code compiles, if you want to see it in action, you will need to deploy it to the webapp root. To do this, from your main development directory, type ant deploy. This will compile any uncompiled PDL or Java code and deploy it to the webapp root. It will also copy into place any new files in your sql/, etc/, and web/ directories.

For development, you may want to enable automatic class reloading in your resin.conf file (you can find this in /var/ccm-devel/web/username/project-name/conf). Otherwise, when you deploy new java classes to the webapp, you will need to type ccm-stop, then ccm-start to get Resin to load your new class files.

If you have unexpected problems once you have loaded your new classes, you may need to "clean" the webapp ( delete the webapp and build directories and compile everything from scratch). This is often a problem when you are moving classes from one package to another. To clean the webapp, type ant clean.

Once your code has deployed and you have tested it, you should check in (commit) your changes to the source code (under dev/username/project-name), either to the local CVS repository or to whatever external version control system you are using.

7.3.4. Handy WAF Aliases

The aliases listed below are automatically created when you do ccm-profile <project-name>. If you need to work on a different project from the same shell, simply do ccm-profile <project-name> for the different project, and these aliases will change appropriately.

7.3.5. Windows® Development Environment

The \ccm\bin\init-profile.cmd command must be run at the beginning of every shell session to set up the proper environment variables. The RPMs add a similar set of environment information to /etc/profile.d.