Maven 依赖插件复制 jar 与依赖
Maven dependency plugin copy jar with dependencies
我正在尝试将 jar 从我的本地存储库复制到另一个项目,如下所述:
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html
但是我的 jar 是从 maven-assembly-plugin 作为 "jar with dependencies" 出来的,它将常规 jar 和组装好的 jar 放在我的本地仓库中。 jar 名称类似于:
example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar
如果我手动复制,我可以在 repo 中找到它并使用它。我认为让maven复制它是个好主意,所以我使用了上面描述的依赖复制目标。
但是我无法让它工作所以它复制了 "jar with dependencies" jar。
pom 是这样的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.group</groupId>
<artifactId>example-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>libs</outputDirectory>
<destFileName>somename.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
我尝试将类型设置为 "jar-with-dependencies",但没有成功。它只有在我将类型设置为 "jar" 时才有效,但随后它会复制常规的未组装 jar。有什么解决办法吗?
如果你有这样的神器:
example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar
您想这样引用它:
<artifactItem>
<groupId>my.group</groupId>
<artifactId>example-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<classifier>jar-with-dependencies</classifier>
<overWrite>true</overWrite>
<outputDirectory>libs</outputDirectory>
<destFileName>somename.jar</destFileName>
</artifactItem>
示例在这里:
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
this---><classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
</artifactItem>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>WEB-INF/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
这会将所有需要的 jar 复制到 WEB-INF/lib ,包括依赖 jar
我正在尝试将 jar 从我的本地存储库复制到另一个项目,如下所述:
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html
但是我的 jar 是从 maven-assembly-plugin 作为 "jar with dependencies" 出来的,它将常规 jar 和组装好的 jar 放在我的本地仓库中。 jar 名称类似于:
example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar
如果我手动复制,我可以在 repo 中找到它并使用它。我认为让maven复制它是个好主意,所以我使用了上面描述的依赖复制目标。
但是我无法让它工作所以它复制了 "jar with dependencies" jar。
pom 是这样的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.group</groupId>
<artifactId>example-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>libs</outputDirectory>
<destFileName>somename.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
我尝试将类型设置为 "jar-with-dependencies",但没有成功。它只有在我将类型设置为 "jar" 时才有效,但随后它会复制常规的未组装 jar。有什么解决办法吗?
如果你有这样的神器:
example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar
您想这样引用它:
<artifactItem>
<groupId>my.group</groupId>
<artifactId>example-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<classifier>jar-with-dependencies</classifier>
<overWrite>true</overWrite>
<outputDirectory>libs</outputDirectory>
<destFileName>somename.jar</destFileName>
</artifactItem>
示例在这里:
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
this---><classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
</artifactItem>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>WEB-INF/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
这会将所有需要的 jar 复制到 WEB-INF/lib ,包括依赖 jar