Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
894 views
in Technique[技术] by (71.8m points)

java - Setting classpath for a JAR

I have a standalone java project. I have performed a maven clean install. I now go into the targetclasses folder via command prompt and set all the required files in classpath. Now I execute the main class. The result is being displayed.

Now I move back to target folder via command prompt and try to execute the jar file (jar file has a manifest file where the main class is defined).

Java -cp %CLASSPATH% -jar Destination-01.19-SNAPSHOT.jar

Now I get the below exception. I have also removed the classpath attribute from the statement above but still get the same exception.The required class is set in classpath variable which is the reason why I was able to run the main class without using the -jar attribute.

Exception in thread "Main Thread" java.lang.NoClassDefFoundError: org/apache/co mons/logging/LogFactory

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It seems -cp and -jar are incompatible. You need to put the classpath in the manifest

See http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

If you want maven to automatically update the classpath, see: -

http://maven.apache.org/shared/maven-archiver/examples/classpath.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...