2016-06-23 53 views
0

我在lib文件夾中創建了一個具有相關jar文件的jar文件。但是當我嘗試使用創建的jar作爲庫時,它將顯示爲「Exception in thread」main「java.lang.NoClassDefFoundError」。如何將所有需要的罐子放入一個最終罐子?

任何人都可以幫我創建一個罐子與依賴罐子?

在此先感謝。

這裏是我的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> 

這是清單的內容在我的jar文件:

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.

+0

你使用maven嗎?這是很容易與maven –

+0

你需要把你的'lib'罐子類路徑 – Sanjeev

+0

你可以看到它。 https://www.youtube.com/watch?v=BsndjGOc1w4 – Rafiq

回答

1

您可以使用maven shade jar來創建一個超級罐子。

或者,也可以不創建1個jar,而是指定包含JARS的文件夾的路徑。參考: - Run a JAR file from the command line and specify classpath

java -cp "jar_name.jar;libs/*" com.test.App應該工作。

+0

我必須創建一個庫jar而不是一個可運行的jar。我的問題是我有四個類和20個依賴jar文件的4個類文件,這些我必須創建一個包含我的4個類和依賴jar的jar文件。然後我的jar文件將被用作庫jar而不是一個可運行的jar ..謝謝你 –