The Slice-to-Java compiler, slice2java, offers the following command-line options in addition to the standard options described in
Section 4.20:
Generate checksums for Slice definitions into the class CLASS. The given class name may optionally contain a package specifier. The generated class contains checksums for all of the Slice files being translated by this invocation of the compiler. For example, the command below causes
slice2java to generate the file
Checksums.java containing the checksums for the Slice definitions in
File1.ice and
File2.ice:
The Ice for Java build system makes extensive use of an ant task named Slice2JavaTask that automates the Slice-to-Java compiler and may also be useful for Ice developers. The task and its supporting classes reside in the JAR file named
ant-ice.jar, which normally can be found in the
lib subdirectory of your Ice installation.
The Slice2JavaTask must be able to locate and spawn the
slice2java executable. You can specify the directory of your Ice installation by defining the
ice.home ant property or the
ICE_HOME environment variable, in which case the task assumes that the Slice compiler’s executable is located in the
bin subdirectory of the specified installation directory. For example, if
ICE_HOME is set to
/opt/Ice on Linux, the task assumes that the executable path name is
/opt/Ice/bin/slice2java. Furthermore, the task also configures its shared library search path (if necessary for your platform) to ensure the executable can resolve its library dependencies.
If both ice.home and
ICE_HOME are defined,
ice.home takes precedence. If neither are defined, the task assumes that the executable can already be found in your
PATH and that your shared library search path is configured correctly.
Finally, you can use a task parameter to specify the full path name of the Slice compiler. Again, the task assumes that your shared library search path is configured correctly.
The task minimizes recompilation by maintaining dependencies between Slice files. The task stores this information in a file named
.depend in the output directory and updates the dependencies after each invocation. (You can specify a different name for this file using a task parameter.)
Note that the task does not maintain dependencies between a Slice file and its generated Java source files. Consequently, removing the generated Java source files does not cause the task to recompile a Slice file. In fact, the task only compiles a Slice file when any of the following conditions are true:
For the flag parameters (ice,
stream, and
tie), legal positive values are
on,
true, or
yes; negative values are
off,
false, or
no.
Define the following taskdef element in your project’s build file to enable the task:
This configuration assumes that ant-ice.jar is already present in ant’s class path. Alternatively, you can specify the JAR explicitly as follows:
This project demonstrates some practices that we encourage you to adopt in your own projects. First, it is helpful to keep the source files generated by the Slice compiler separate from your application’s source files by dedicating an output directory for the exclusive use of the Slice compiler. Doing so helps to minimize confusion and makes it easier to configure a source-code management system to ignore generated files.
Next, we also recommend that you include a clean target in your ant project that removes this output directory. Assuming that the dependency file (
.depend) is also stored in this directory, removing the output directory is an efficient way to clean up your project’s source tree and guarantees that all of your Slice files are recompiled in the next build.
Finally, after seeing the exclude element in the invocation of
javac you might infer that the generated code was not being compiled, but the presence of the output directory in the
srcdir attribute ensures that the generated code is included in the build. The purpose of the
exclude element is to prevent ant from including the generated files twice in its target list.