error running java in another dir from ant
I have a simple class, FabricClient, in the package client, with a public static void main(). This package is in the开发者_如何学Go 'bin' directory of my project. From the bin directory, on the command line, I can execute the main in this class as follows:
user@sys /c/projects/myproject/bin
$ java -classpath .;c:\dir\my.jar client.FabricClient
I want to execute my ant build.xml file from the parent directory (/c/projects/myproject) from where I run the java command by hand. I've tried using the dir attribute as follows:
<target name="run-client">
<java classname="client.FabricClient"
classpath="${classpath}"
fork="true"
failonerror="true"
dir="./bin">
</java>
</target>
My classpath variable does have the current directory as well as the directory of my.jar as used on the command line (my ant command to compile the class works fine with the same variable)
Here are the settings used to generate the classpath
<property name="my.jar" location="c:\dir\my.jar" />
<property name="classpath" location=".:${my.jar}:." />
I'm getting the typical java.lang.NoClassDefFound Error: client/FabricClient
I'm using Ant version 1.7.0
If I move the build.xml file into bin and remove the dir attribute, it works fine. Can you run java from a directory other than the local directory? I thought this was what the dir attribute did.
Paths in ant are usually referred like this:
<java classname="client.FabricClient"
fork="true"
failonerror="true"
dir="./bin">
<classpath>
<pathelement location="C:/dir/my.jar"/>
</classpath>
it is more readable and reliable
Your classpath should contain the file my.jar, not the directory where my.jar is.
精彩评论