2

我正在创建一个jar-with-dependenciesin 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>

4

1 回答 1

2

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

现在将此 lib 文件夹标记为“资源”文件夹。喜欢,

<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> 
于 2013-06-04T12:56:13.560 回答