创建一个jar-with-dependencies

时间:2013-06-04 12:47:33

标签: java maven

我在jar-with-dependencies中创建mvn 3.0.3。我已经在一个项目中成功完成了这个(仅使用mvn install)并创建了一个完整的jar-wth-dependencies。我将相关的POM代码块(<plugins>...</plugins>,其他人写的!)复制到当前项目(不同之处在于它有程序集)。它会创建正常的快照jar(jumbo-converters-compchem-gaussian-0.3-SNAPSHOT.jar),但不会创建jar-with-dependencies。我该如何修改POM?

<?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>

1 个答案:

答案 0 :(得分:2)

首先, 使用maven依赖项插件检索/存储依赖项(更多信息here)到项目文件夹。 例如:说lib文件夹。

现在将此lib文件夹标记为“Resources”文件夹。 像,

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

现在mvn install应该包含最终工件中的依赖项。 (将Shinchan的评论复制到这里,以便格式化:

  

简单地将此添加到你的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> 
相关问题