0

I would like to include an external jar (specified in the dependencies) inside the jar with dependencies.

pom.xml dependency:

<dependency> <groupId>my.package</groupId> <artifactId>my-artifact</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${basedir}\..\lib\my-artifact.jar</systemPath> </dependency>

Here is the code for jar-with-dependencies:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>CtrlpConversion</id> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>my.package.Main</mainClass> <packageName>my.package</packageName> </manifest> </archive> <finalName>MyExecutable</finalName> <appendAssemblyId>false</appendAssemblyId> </configuration> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>

The .jar generated by this pom.xml does not include the classes of my-artifact.jar. And when I try to run the main I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: my/package/ClassThatINeed at my.package.Main.main(Main.java:29) Caused by: java.lang.ClassNotFoundException: my.package.ClassThatINeed 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) ... 1 more

I would love to have some help in finding the solution to this issue. Thank you!!

Andrea
  • 155
  • 1
  • 1
  • 9
  • You need to configure classpath in your jar;s manifest file please refer to link I duplicated with – jmj May 28 '14 at 00:29
  • Are the classes actually missing? Open up the jar file using a zip utility and see if they are actually in there. Chances are, your manifest file has an incorrect classpath. – Ryan J May 28 '14 at 00:30
  • Jigar, I've added true but I'm having the same identical behavior. – Andrea May 28 '14 at 00:52
  • Ryan, the classes are actually missing in the JAR – Andrea May 28 '14 at 01:02
  • So `my.package.ClassThatINeed` is there in your MANIFEST.mf's classpath entry relatively? – jmj May 28 '14 at 02:19
  • The class is not in the jar file. (Like the other dependencies I have). – Andrea May 28 '14 at 17:19
  • then where is the java source located in project directory structure ? – jmj May 30 '14 at 03:06

0 Answers0