0

I am currently trying to make a Jar with all my libraries included. What I have done, I have created folders like this :

eancopy (which contain all my classes)
lib (containing all my libraries : mongo, jedis...)
META-INF/MANIFEST.MF

My main class is named process (within the package eancopy)

My manifest is like this:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Class-Path: lib\commons-pool-1.5.6.jar lib\jedis-2.0.0.jar lib\mongo-2.6.3.jar
Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.)
Main-Class: eancopy.process

I have generated the JAR with this command :

jar cvmf META-INF/MANIFEST.MF EANcopy.jar eancopy/*.class lib/*.jar

My problem : When executing the JAR by java -jar EANcopy.jar, it works when it is executed in the place where I have generated the JAR but in another place I have the message :

Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBObject
Caused by: java.lang.ClassNotFoundException: com.mongodb.DBObject
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: eancopy.process. Program will exit.

Any ideas ? Thanks

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
kozher
  • 695
  • 4
  • 10
  • 18

1 Answers1

0

This exception shows you the cause of the problem:

Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBObject

You haven't specified these libs lib\commons-pool-1.5.6.jar lib\jedis-2.0.0.jar lib\mongo-2.6.3.jar in your CLASSPATH environment variable, hence why it fails when run in other places.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228