2016-07-29 57 views
0

我想創建一個可執行的jar包含我的外部jar。 我已經閱讀下文提到的文章,但對我來說,這個外部JAR我必須使用如下: #MYGROUP# #myArtifact# #VERSION# 系統 $ {} project.basedir/lib目錄/#myjar#.jar 由於systemPath,我必須使用範圍系統,這就是爲什麼我的jar不會包含在我的最終可執行jar文件中。 當我嘗試運行我的jar時,它會以NoClassDefFoundError結束到我的外部jar。 你能幫我一下,如何將我的外部jar包含到我的最終可運行jar中。maven創建與外部庫的脂肪罐

Here is my current plugins: 
<!-- compiler plugin --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>${jdk.version}</source> 
        <target>${jdk.version}</target> 
       </configuration> 
      </plugin> 

      <!-- Make this jar executable --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <mainClass>#MYMAINCLASS#</mainClass> 
          <classpathPrefix>lib/</classpathPrefix> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 

      <!-- Copy project dependency , can be used when we have repository.--> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.5.1</version> 
       <executions> 
        <execution> 
         <id>copy-dependencies</id> 
         <phase>prepare-package</phase> 
         <goals> 
          <goal>copy-dependencies</goal> 
         </goals> 
         <configuration> 
<outputDirectory>${project.build.directory}/lib</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

Thanks you answer in advance! 

http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven 
https://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/ 

回答

0

將您的外部jar手動安裝到您的存儲庫,然後使用默認範圍內的jar,那將是最簡單的解決方案。

mvn install:install-file -Dfile=<path-to-file> \ 
         -DgroupId=<myGroup> \ 
         -DartifactId=<myArtifactId> \ 
         -Dversion=<myVersion> \ 
         -Dpackaging=<myPackaging> 

而且你還可以參考其他可能的辦法here