Why can't run?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Successful:
C:\test>java -jar Test.jar
INFO (Test) - haha
Failure:
C:\test>ant -buildfile test.xml
run:
[java] java.lang.NoClassDefFoundError: org/apache/log4j/Logger
[java] at Test.<clinit>(Unknown Source)
[java] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[java] ... 1 more
[java] Could not find the main class: Test. Program will exit.
[java] Exception in thread "main"
[java] Java Result: 1
test.xml:
<target name="run" depends="">
<java jar="Test.jar" fork="true"/>
</target>
why? i am trying to solve it two days, please for help.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
[My Blog]
All roads lead to JavaRanch
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Christophe Verré wrote:Ant cannot find log4j's library. You have to set the classpath dependencies in your build.xml. Check this tutorial (Using external libraries).
Hi,thanks for your reply. i know what you mean. but you can see the first runs ok, but the second runs meeting an error. why?
my Test.jar contains below:
Test.class
log4j-1.2.14.jar
log4j.properties
META-INF
i still confused.thank you.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I see this thread has been (correctly) moved to the "ANT" forum.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Christophe Verré wrote:Where is your manifest file ? What does it contain ?
Thanks very much for your kindly reply. my project works all right now, but i still have some questions to ask you.
build.xml
please see run target: when i used <java jar="${build.lib}/${Main-class}.jar" fork="true"/> i will meet the "NoClassDefFoundError", why,even i have modified the
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Campbell Ritchie wrote:Welcome to the Ranch
I see this thread has been (correctly) moved to the "ANT" forum.
yes,you are right, it's a mistake. i am fresher.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Christophe Verré wrote:You still have to set the dependency in your MANIFEST file. Try to use this instead :
Hi,if follow this, it is still wrong. whatever i modify.
why?
Test.jar contains below:
Test.class Log4j.properties log4j-1.2.14.jar META-INF
MANIFEST.MF contains below:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 17.0-b17 (Sun Microsystems Inc.)
Built-by: Yancy
Main-class: Test
Class-Path: log4j-1.2.14.jar
what's wrong? thanks a lot.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It would be so much simplier if you kept the log4j JAR outside of your own JAR
Do you need to put it inside ?[My Blog]
All roads lead to JavaRanch
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Christophe Verré wrote:Try "java classname="${Main-class}" fork="true"" instead of "java jar="${build.lib}/${Main-class}.jar" fork="true"".
It would be so much simplier if you kept the log4j JAR outside of your own JARDo you need to put it inside ?
you are very kind! Thanks very much. but i still want to know why? Because when i go deep into the question, i find a more confused problem: i move the Test.jar to the C:\test
Test.jar contains: Test.class Log4j.properties META-INF
MANIFEST.MF contains below:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 17.0-b17 (Sun Microsystems Inc.)
Built-by: Yancy
Main-Class: Test
(no dependency on log4j.jar)
Successful:
C:\test>java -jar Test.jar
INFO (Test) - haha
Failure:
C:\Java\jdk1.6.0_21\bin>java.exe -jar C:\test\Test.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at Test.<clinit>(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 1 more
Could not find the main class: Test. Program will exit.
it makes me so surprised! i just want to know why?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Execute C:\Java\jdk1.6.0_21\bin>java.exe -jar C:\test\Test.jar
would not include the log4j libaray
Execute C:\test>java -jar Test.jar
would do because the log4j library is on the current path "C:\test"
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Raymond Tong wrote:Because your log4j jar is located in C:\test
Execute C:\Java\jdk1.6.0_21\bin>java.exe -jar C:\test\Test.jar
would not include the log4j libaray
Execute C:\test>java -jar Test.jar
would do because the log4j library is on the current path "C:\test"
thanks for you reply, but log4j.jar is not located in C:\test,it is not as easily as you think. i put log4j.jar to the jre/lib/exc. So the two ways of execute should be the same, but the results are quite different, i wanna to see why? thanks all the same~
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Martijn Verburg wrote:Hi Yancy,
Just so you know it's really not recommended to put 3rd party JARs in the JRE folders, they should be kept elsewhere and referenced as needed.
yes,you are right,very thanks~
| Don't listen to Steve. Just read this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |








