-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.

Asfbar
  • 259
  • 6
  • 21
  • 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. – StackFlowed Dec 29 '15 at 19:01
  • 1
    Possible duplicate of [Why am I getting a NoClassDefFoundError in Java?](http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – StackFlowed Dec 29 '15 at 19:03
  • i used maven. but where is the mainfest file? i don't find it. – Asfbar Dec 29 '15 at 19:06
  • Should be in your target folder ... Just try mvn clean install it should regenerate it. – StackFlowed Dec 29 '15 at 19:08
  • already did it but it did not help – Asfbar Dec 29 '15 at 19:11
  • does you pom pull in the right jar ? and the import statement pulls in the right class ? – StackFlowed Dec 29 '15 at 19:23
  • sorry, didn't understand your question: does you pom pull in the right jar – Asfbar Dec 29 '15 at 19:35
  • pom.xml has the correct jar in its dependencies ? – StackFlowed Dec 29 '15 at 20:50
  • yes it has. i double checked that. that's why when i put my app in the lib directory (where maven download the jars to) it working perfect. – Asfbar Dec 29 '15 at 21:38

1 Answers1

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

Community
  • 1
  • 1
Andrew Williamson
  • 8,299
  • 3
  • 34
  • 62
  • {java -cp cloneXl-0.0.1.jar:lib/*:. com.xxx.myJavaTraining.CloneXL Error: Could not find or load main class com.xxx.myJavaTraining.CloneXL} – Asfbar Dec 29 '15 at 19:12
  • That's weird... try: java -cp cloneXl-0.0.1.jar:lib:. com.xxx.myJavaTraining.CloneXL – Andrew Williamson Dec 29 '15 at 19:21
  • 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. – Andrew Williamson Dec 29 '15 at 19:37