我正在尝试为一个小实用程序集创建一个maven配置,这个实用程序集将实用程序以及它们的依赖jar(在这种情况下到目前为止只有一个)。我已经阅读了有关uberjars,shade,assembly等的内容。但是,我无法将依赖的jar放入主jar中。我对maven相当新,并且从来不需要像这样捆绑依赖的罐子。我有一个配置,将运行并生成一个jar但我不能让依赖项jars显示在目标中,因为我假设他们应该?所以,我认为我要么接近也许要进行调整或者做些什么。或者,我只是完全离开,也可能是这种情况。
这是当前的配置:
<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>
那里还有一个程序集插件,但它被注释掉了。这对我也不起作用。构建将运行并生成构建,但似乎永远不会出现依赖项的内容。
关于我遗失或搞砸的任何想法?
答案 0 :(得分:0)
最重要的原因:您已将maven-dependency-plugin
置于pluginManagement标记内。简单来说:pluginManagement中的插件是预先配置的插件,只有在显式调用它们时才会使用。这适用于maven-compiler-plugin和maven-jar-plugin,因为这些插件已经绑定到jar的默认构建生命周期(由Maven完成)。如果您将maven-dependency-plugin移动到<project><build><plugins>
,那么在调用mvn package
时它会被接收。