-1

i'm new with java. when i come to run my java app i'm getting this error below:

java.lang.NoClassDefFoundError: org/apache/poi/EncryptedDocumentException

the issue it is ALSO happens when i'm adding the classpath to my command:

java -jar myApp.jar -classpath .\lib

BUT, when i'm copy myApp.jar to the lib direcotry and running form there it's working fine.

thanks for the help guys.

9
  • What build tool are you using ? you need to make sure that org/apache/poi/EncryptedDocumentException is in the runtime class path. If you are using maven the delete your old manifest and do a mvn clean install on your project to regenerate it. Commented Dec 29, 2015 at 19:01
  • 1
    Possible duplicate of Why am I getting a NoClassDefFoundError in Java? Commented Dec 29, 2015 at 19:03
  • i used maven. but where is the mainfest file? i don't find it. Commented Dec 29, 2015 at 19:06
  • Should be in your target folder ... Just try mvn clean install it should regenerate it. Commented Dec 29, 2015 at 19:08
  • already did it but it did not help Commented Dec 29, 2015 at 19:11

1 Answer 1

1

You cannot use both -jar and -classpath at the same time. If you use -jar, it will ignore your -classpath and use settings from the manifest in the jar. Try all in the classpath:

java -cp myApp.jar:lib/*:. mypackage.MyClass

On Windows you need to use ';' instead of ':'

java -cp myApp.jar;lib/*;. mypackage.MyClass

See similar question here: Execute jar file with multiple classpath libraries from command prompt

Sign up to request clarification or add additional context in comments.

3 Comments

{java -cp cloneXl-0.0.1.jar:lib/*:. com.xxx.myJavaTraining.CloneXL Error: Could not find or load main class com.xxx.myJavaTraining.CloneXL}
That's weird... try: java -cp cloneXl-0.0.1.jar:lib:. com.xxx.myJavaTraining.CloneXL
Is this being run from the same directory that the jar lives in? Since it's being specified by -cp, it won't warn you if the path doesn't point to anything. Also, double-check the jar - if you open it, does it contain the class you are intending to use? Other than that, I'm out of ideas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.