2013-06-04 66 views
2

我在mvn 3.0.3中創建jar-with-dependencies。我已經在一個項目中成功完成了這個任務(僅使用mvn install),並創建了一個完整的jar-wth-dependencies。我將相關的POM代碼塊(<plugins>...</plugins>,別人寫的!)複製到當前項目(不同之處在於它有程序集)。它會創建正常的快照jar(jumbo-converters-compchem-gaussian-0.3-SNAPSHOT.jar),但不會創建jar-with-dependencies。我應該如何修改POM?創建jar -with-dependencies

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>cml</groupId> 
    <artifactId>jumbo-converters</artifactId> 
    <version>0.3-SNAPSHOT</version> 
    <relativePath>../../pom.xml</relativePath> 
</parent> 

<artifactId>jumbo-converters-compchem-gaussian</artifactId> 
<name>jumbo-converters-compchem-gaussian</name> 

<dependencies> 
    <dependency> 
     <groupId>${jumbo.groupId}</groupId> 
     <artifactId>jumbo</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>cml</groupId> 
     <artifactId>jumbo-converters-core</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>cml</groupId> 
     <artifactId>jumbo-converters-compchem-common</artifactId> 
     <version>0.3-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
     <groupId>cml</groupId> 
     <artifactId>jumbo-converters-templates</artifactId> 
     <version>0.3-SNAPSHOT</version> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>cml</groupId> 
     <artifactId>jumbo-converters-testutils</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>cml</groupId> 
     <artifactId>jumbo-converters-compchem-testutils</artifactId> 
     <scope>test</scope> 
    </dependency> 

</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <mainClass>org.xmlcml.cml.converters.compchem.gaussian.GaussianLogXML2CompchemConverter</mainClass> 
        </manifest> 
       </archive> 
       <excludes> 
        <exclude>.hgsub</exclude> 
        <exclude>**/.hg/</exclude> 
        <exclude>**/.project</exclude> 
        <exclude>**/external/</exclude> 
       </excludes> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
       <archive> 
        <manifest> 
         <mainClass>org.xmlcml.cml.converters.compchem.gaussian.GaussianLogXML2CompchemConverter</mainClass> 
        </manifest> 
       </archive> 
       <excludes> 
        <exclude>.hgsub</exclude> 
        <exclude>**/.hg/</exclude> 
        <exclude>**/.project</exclude> 
        <exclude>**/external/</exclude> 
       </excludes> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

+2

您是否嘗試過'MVN組件:single' – joaonlima

+0

號我會努力它(以前從未使用過它) –

回答

2

首先, 使用Maven Dependency插件來檢索/存儲的依賴關係(更多信息here)到項目文件夾。例如:說lib文件夾。

現在將這個lib文件夾標記爲「Resources」文件夾。 一樣,

<resources> 
    <resource> 
    <directory>lib</directory> 
    <targetPath>lib</targetPath> 
    </resource> 
</resources> 

現在MVN安裝應該包括在最終神器的依賴關係。 (複製蠟筆小新的評論在這裏,因此它可以被格式化:

簡單這烏爾POM加

<build> 
    <resources> 
     <resource> 
      <directory>lib</directory> 
      <targetPath>lib</targetPath> 
     </resource> 
    </resources> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.8</version> 
      <executions> 
       <execution> 

        <phase>install</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>lib</outputDirectory> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
+0

簡單將其添加到烏爾POM。 \t \t \t \t \t \t \t \t \t LIB \t \t \t \t LIB \t \t \t \t \t \t \t \t \t \t \t \t \t \t org.apache.maven.plugins \t \t \t \t 行家依賴性-插件 \t \t \t \t 2。8 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 安裝 \t \t \t \t \t \t \t \t \t \t \t \t \t 複製依賴性 \t \t \t \t \t \t \t \t \t \t \t \t <結構> \t \t \t \t \t \t \t <輸出目錄> LIB \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t Shinchan