<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
Why I cannot use something like
<java jar="build/jar/HelloWorld.jar" fork="true" >
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
I received the error like
[java] java.lang.NoClassDefFoundError: org/apache/log4j/Logger [java] at oata.HelloWorld.(Unknown Source) [java] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
According to the
javatask documentation, your second example should just work as expected (except that theclasspathwill be ignored).Edit: The information you added to your question implies a few things:
.jarfile is foundMain-Classentry in its manifestClass-Pathentry pointing to alog4j.jarfileBasically the
javaant task has the same requirements as usingjava -jaron the command line: if your.jarfile doesn’t correctly run usingjava -jar myApp.jaron the command line, then thejavaAnt task won’t work like that either.Edit 2: Whenever you invoke a
.jarfile directly in Java, then no further classpath can be specified in any way. That’s true when you usejava -jar myApp.jarand it’s also true when you use thejavaAnt task with thejarattribute. That means that the.jarfile itself must have a correctClass-Pathentry.