HFOSS 2010 Coding Case Study

Back to workshop details

Making HCryptoJ into an Ant project
Here is what we learn from the README with respect to compilation: To compile all the files in ./source and store the classes in the ./classes, which must already exist, use the following command. This assumes that you are presently in this directory.

javac -d classes -classpath src src/hcrypto/cipher/*.java \ src/hcrypto/provider/*.java src/hcrypto/engines/*.java \ src/hcrypto/analyzer/*.java src/applications/*.java \ src/applications/cryptotoolj/*.java src/pluginproviders/*.java

This, alas, is incorrect information the way HCryptoJ is distributed. We'll start to make it correct by making the src directory and moving the appropriate directories into it: hcryptoj$ mkdir src hcryptoj$ mv applications hcrypto pluginanalyzers plugins src

It is also the case that the compile line above is not quite correct, as it forgets about the source code in subdirectories of src/hcrypto/analyzer; to get those, we need to add src/hcrypto/analyzer/*/*.java in the list of source code to compile. And as it happens, the -classpath flag is unnecessary.

Making this into an Ant project is quite easy, and makes building much simpler. The basic idea is that the project specification is an XML file; the main nodes are target nodes in which you specify what can be done (such as building, cleaning, etc.), and within those nodes one specifies a series of tasks. The tasks are defined by Ant. Here is a simple build file for HCryptoJ:





 

  <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true"> <src path="${src.dir}"/>

<target name="clean" description="Remove generated files" > <delete dir="${build.dir}" includeemptydirs="true" />

Create a file named build.xml</tt> in the top level of your HCryptoJ distribution (i.e., the directory that contains src</tt>). Now you can build the project with hcryptoj$ ant build

and clean the project with hcryptoj$ ant clean

And that's all there is to it!

Looking at the project in Eclipse
First, download the Eclipse IDE; I recommend the EasyEclipse distribution, which provides pre-configured versions. For this project, I would suggest the "Expert Java" distribution.

Before starting Eclipse, create a directory to use as your Eclipse workspace, and copy the HCryptoJ project into the workspace: somewhere$ mkdir workspace somewhere$ cp -rp hcryptoj workspace (assuming somehwere</tt> is the directory containing hcryptoj</tt> and hcryptoj</tt> is your HCryptoJ directory.

Now start Eclipse; when it asks you for a workspace directory, point it to the workspace directory that you created above.

Now make hcryoptj</tt> into a project in your Eclipse workspace:
 * Select "New Project..."
 * Untie the Java twistie and select "Java Project."
 * For "Project Name" use hcryptoj</tt>.
 * Select "Create project from existing source" and browse to select the hcryptoj</tt> directory that you created inside workspace</tt>.
 * Select "Finish."

Because this is an Ant project that we have imported into Eclipse, the Eclipse "Build" menu doesn't help much. Instead, to make use of Ant (which is built into Eclipse), go to "Window->Show view->Ant" to get a new subwindow for use with Ant. Drag build.xml</tt> from the Package Explorer view to the Ant view. You should now see the various Ant targets, and double-clicking on a target will invoke that target.

To run CryptoToolJ, we have to create a Run Configuration. Select "Run->Run..." Then select "Java Application" and click on the "New launch configuration button" (look at the tooltips for the buttons). Name the Run Configuration CryptoToolJ</tt> and set the "Main class" to applications.cryptotoolj.CryptoToolJ</tt>. Then select "Apply" and "Run." From now on, you can choose this Run Configuration from the "Run->Run History."

As long as we're here, let's create another target in build.xml</tt>. This one creates an executable JAR file that automatically runs CryptoToolJ</tt>. Right- (or Control-) click on build.xml</tt> and select "Open" or "Open With->Ant Editor." Add the following target: <property name="jar.file" value="hcrypto-0.51.jar" /> ...   <target name="buildjar" description="Build executable JAR file" depends="build"> <jar destfile="${jar.file}" basedir="${build.dir}"> <attribute name="Main-Class" value="applications.cryptotoolj.CryptoToolJ" />