concept < java in category ant

appears as: <java, <java, The <java
Ant in Action

This is an excerpt from Manning's book Ant in Action.

We have three <arg> tags inside the <java> task; each tag contains one of the arguments to the program: "a", "b", and ".", as with the command-line version. Note, however, that the final argument, <arg file="."/>, is different from the other two. The first two arguments use the value attribute of the <arg> tag, which passes the value straight down to the program. The final argument uses the file attribute, which tells Ant to resolve that attribute to an absolute file location before calling the program.

Ant’s execution services come in three tasks, <java>, <exec>, and <apply>, that together meet most projects’ needs for running Java and native code. Let’s start with an overview of the problem, get into <java>, and then look at native code.

You can set environment variables inside <java>, <junit> and <exec> by using the element <env>. The syntax of this element is identical to that of the <sysproperty> element:

<java classname="d1.core.DiaryMain"
  classpathref="run.classpath"
  fork="true">
  <env key="JAVA_HOME" value="${user.home}/JDK" />
  <env key="PATH" path="${dist.dir};${env.PATH}"/>
  <env key="Path" path="${dist.dir};${env.Path}"/>
  <arg value="2006-06-31-08:30" />
  <arg file="." />
  <arg path="${user.home};/" />
</java>

In <java> and <junit>, the PATH environment variable controls where native libraries are loaded by the JNI facility. Setting the path on a forked program—and it must be forked—lets us load new JNI libraries in the program that’s run by <java>.

Oops! We left out the classpath and get to see Ant’s error message when this happens. Welcome to classpath-related pain. If you’re new to Java, this will be a new pain, but to experienced Java developers, it should be a very familiar sensation. To run our program, we have to set up the classpath for <java>.