如何使用Maven分发依赖jar?

时间:2014-04-02 17:00:51

标签: maven

我下载了一个Maven项目,可以运行mvn install来构建目标helloworld.jar,这取决于几个第三方运行时jar。但是,我不确定如何使用Maven自动将这些第三方jar复制到特定目录中。查看pom.xml,我发现了以下语句。所以我基本上希望将第三方罐子复制到${project.build.directory}/lib。要做到这一点,我应该使用哪个maven插件/短语/目标?有人能告诉我一个可运行的maven语法吗?谢谢!

<profile>
    <id>build</id>
    <activation>
        <activeByDefault>false</activeByDefault>
    </activation>
    <properties>
        <maven.test.skip>false</maven.test.skip>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependency-jar</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>log4j</groupId>
                                    <artifactId>log4j</artifactId>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>
                                        ${project.build.directory}/lib
                                    </outputDirectory>
                                    <destFileName>
                                        log4j.jar
                                    </destFileName>
                                </artifactItem>


                                <artifactItem>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <version>${project.version}</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>
                                        ${project.build.directory}/lib
                                    </outputDirectory>
                                    <destFileName>
                                        helloworld.jar
                                    </destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</profile>

1 个答案:

答案 0 :(得分:0)

此处提供了POM文件中指定的插件的可用构建目标列表:

https://maven.apache.org/plugins/maven-dependency-plugin/usage.html

我怀疑你想要依赖:copy-dependencies