-3

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
manlio
  • 18,345
  • 14
  • 76
  • 126
user3386486
  • 3
  • 1
  • 3

1 Answers1

1

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.

Salah
  • 8,567
  • 3
  • 26
  • 43
  • I added a folder lib contains my .jar at the same level of src, I exported again the .jar . When i extract the .jar, i see folder lib inside but I have de same problem, please some idea? Help me – user3386486 Mar 06 '14 at 14:40
  • You don't have to add any thing, just make sure when you export the jar file, it export also the third part libraries jars. – Salah Mar 06 '14 at 15:05
  • Please salah can you give me more details. The informations (user and password) of my server are inside a file.ini and i use jsch-0.1.42.jar and jcsv-1.4.0.jar. My .jar giis not solved – user3386486 Mar 06 '14 at 16:37
  • Are you sure that you added this jars to your project. – Salah Mar 07 '14 at 11:27
  • I'll tell you the steps that your project should work fine. see my updated answer. – Salah Mar 07 '14 at 21:38
  • now I have a security problem, In my project there is a file .ini that contains informations (password and user) about the connexion to my server. When I extract the .jar, the file show password and user connexion. I don't want that the person who will run .jar see that information. How can i solved it? – user3386486 Mar 10 '14 at 14:13
  • This may help you [How to access file in jar file](http://stackoverflow.com/questions/5171957/access-file-in-jar-file) – Salah Mar 10 '14 at 14:24
  • Please I want to refused Access file in jar file to user of jar. – user3386486 Mar 10 '14 at 17:52
  • because if the user have access, he can have password of server. – user3386486 Mar 10 '14 at 17:53
  • my file .ini is in my project/src – user3386486 Mar 10 '14 at 17:57
  • Then you need to check the current user logged in, if he one of those who have access then execute that code that access the file, else don't execute it. – Salah Mar 10 '14 at 18:20
  • Thank you for the answer of first question. – user3386486 Mar 13 '14 at 19:20