Maven 试图用jar绑定依赖项
我正在尝试为一个小的实用程序集创建一个maven配置,它将jar这些实用程序以及它们的依赖jar(到目前为止,在本例中只有一个)。我已经通读了Uberjar、shade、Assembly等的内容,但是,我无法将依赖的jar打包到主jar中。我是maven的新手,从未需要像这样捆绑依赖JAR。我有一个配置可以运行并生成一个jar,但是我不能让依赖项jar显示在目标中,因为我假设它们应该显示在目标中?所以,我想我要么很接近,也许有点小调整或者做点什么。或者,我只是完全离开了,也可能是这样 以下是当前配置:Maven 试图用jar绑定依赖项,maven,maven-2,Maven,Maven 2,我正在尝试为一个小的实用程序集创建一个maven配置,它将jar这些实用程序以及它们的依赖jar(到目前为止,在本例中只有一个)。我已经通读了Uberjar、shade、Assembly等的内容,但是,我无法将依赖的jar打包到主jar中。我是maven的新手,从未需要像这样捆绑依赖JAR。我有一个配置可以运行并生成一个jar,但是我不能让依赖项jar显示在目标中,因为我假设它们应该显示在目标中?所以,我想我要么很接近,也许有点小调整或者做点什么。或者,我只是完全离开了,也可能是这样 以下是当前
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maventest</groupId>
<artifactId>RejectFileProcessor</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>RejectFileProcessor</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.6</java-version>
<srcDir>src</srcDir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${srcDir}</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.dst.reject.RejectFileCleaner</mainClass>
<classpathPrefix>dependency-jars/</classpathPrefix>
</manifest>
</archive>
<finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
</plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assembly/uberJar.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.dst.reject.RejectFileCleaner</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>dependency-jars/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.apache.commons</includeGroupIds>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
4.0.0
com.maventest
拒绝文件处理器
罐子
1
拒绝文件处理器
http://maven.apache.org
1.6
src
org.apache.commons
commons-lang3
3.1
编译
${srcDir}
org.apache.maven.plugins
maven编译器插件
2.3.2
${java版本}
${java版本}
org.apache.maven.plugins
maven jar插件
2.3.2
包裹
罐子
真的
com.dst.reject.RejectFileCleaner
依赖罐子/
${project.artifactId}-${project.version}
org.eclipse.m2e
生命周期映射
1.0.0
org.apache.maven.plugins
maven依赖插件
[2.0,)
复制依赖项
org.apache.maven.plugins
maven依赖插件
2.5.1
复制依赖项
包裹
复制依赖项
org.apache.commons
${project.build.directory}/dependency jars/
那里仍然有一个汇编插件,但是它被注释掉了。这对我来说也不起作用。这个构建将运行并生成一个构建,但似乎从来没有遇到依赖项的问题
关于我遗漏了什么或搞错了什么,你有什么想法吗?最重要的原因:你把
maven依赖插件
放在了pluginManagement标签中。简单地说:pluginManagement中的插件是预配置的插件,只有在显式调用它们时才使用。这适用于maven编译器插件和maven jar插件在中,因为这些插件已经绑定到JAR的默认buildlifecycle(由Maven完成)。如果您将maven dependency插件移动到
,则在调用mvn package
+1时,它将被拾取。谢谢。我最初没有插件管理,因为我认为我不需要它,但没有它,dependency插件会给我以下内容:maven dependency插件(目标“复制依赖项”m2e不支持“,”unpack“)。这只是一个警告,说明此插件与Eclipse的集成不是最佳的。我建议改为使用maven shade插件,这是用于此目的最强大的插件。再次声明:不要将其置于插件管理之下。