Question

Good Morning, I have a problem when I try to execute my .jar. My program read some file from distant server by JSch.

C:\Documents and Settings\julie\Bureau>java -jar myFile.jar 

Exception in thread "main" java.lang.NoClassDefFoundError: com/jcraft/jsch/SftpE xception         
at java.lang.Class.getDeclaredMethods0(Native Method)         
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)         
at java.lang.Class.getMethod0(Unknown Source)         
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)     
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException: com.jcraft.jsch.SftpException    
at java.net.URLClassLoader$1.run(Unknown Source)     
at java.net.URLClassLoader$1.run(Unknown Source)    
at java.security.AccessController.doPrivileged(Native Method)     
at java.net.URLClassLoader.findClass(Unknown Source)   
at java.lang.ClassLoader.loadClass(Unknown Source)      
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)     
at java.lang.ClassLoader.loadClass(Unknown Source)         
... 6 more
Was it helpful?

Solution

You have a missing classes in this package : com.jcraft.jsch.

If this package come from a third part library, then make sure that the jar contais this package inside a lib folder at the same level of your executable jar.

[Edit]

First: to add a third part jars in eclipse:

  1. Right click on your project
  2. Select properties -> Java Build Path -> Libraries tap.
  3. Select Add External JARs
  4. Navigate to your jars and press OK

Second: to generate an executable Jar file:

  1. Right click on your project
  2. Select Export -> Java -> Runnable JAR File.

This should work just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top