0

I have created a jar file with dependent jar files in lib folder.But when I try to use the created jar as a library,It will show like "Exception in thread "main" java.lang.NoClassDefFoundError".

Can anyone help me to create a jar with dependent jars?

Thanks in advance.

Here is my pom.xml: `

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <properties>
      <jclouds.version>1.9.2</jclouds.version>
   </properties>
   <groupId>org.apache.jclouds.examples</groupId>
   <artifactId>openstack-examples</artifactId>
   <version>1.0</version>
   <build>
      <plugins>
         <!-- any other plugins -->
         <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.1</version>
            <configuration>
               <descriptorRefs>
                  <descriptorRef>jar-with-dependencies</descriptorRef>
               </descriptorRefs>
            </configuration>
            <executions>
               <execution>
                  <id>make-assembly</id>
                  <!-- this is used for inheritance merges -->
                  <phase>package</phase>
                  <!-- append to the packaging phase. -->
                  <goals>
                     <goal>attached</goal>
                     <!-- goals == mojos -->
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
</project>

This is the contents of MANIFEST in my jar file:

Manifest-Version: 1.0 
Archiver-Version: Plexus Archiver
Built-By: root
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_25 

Here I add the image for structure of my jar file.

1 Answers1

1

You can use maven shade jar to create an uber jar.

Alternatively, instead of creating 1 jar, you can specify the path of the folder containing the JARS. Refer :- Run a JAR file from the command line and specify classpath

Something like java -cp "jar_name.jar;libs/*" com.test.App should work.

Community
  • 1
  • 1
Jaiprakash
  • 599
  • 2
  • 7
  • I have to create a library jar not a runnable jar.My issue is I have four class and 20 dependent jar files for that 4 class files,with these i have to create a jar file that include my 4 classes and dependent jars.Then my jar file will be used as library jar not a runnable jar..Thank u – Suba Lakshmi Jun 23 '16 at 10:46