我一直在研究最终创建可执行jar文件的Java Maven项目。起初,我没有问题,但后来我决定我想将依赖关系复制到jar中。如何创建一个具有依赖性的jar作为主构建工件,稍后由assembly插件使用?
我发现下面的(非常有用)栈溢出问题,随后在回答中提供的说明(代我自己的主类和目标版本):Problem building executable jar with maven
这奇妙的工作,但我结束了两个jar文件(ldap-daemon-0.0.1-SNAPSHOT.jar和ldap-daemon-0.0.1-SNAPSHOT-jar-with-dependencies.jar)。我可以肯定这一点,但据我所知,我实际上无法在以后使用maven-dependency-plugin的复制功能获得具有依赖项的jar副本。
所以,我想知道的是如何完成下列操作之一:
- 有我的主构建神器,LDAP守护-0.0.1-SNAPSHOT.jar,包括它的依赖
- 使用maven-dependency-plugin复制第二个构建工件(ldap-daemon-0.0.1-SNAPSHOT-jar-with-dependencies.jar)。
下面是LDAP守护我的插件配置(包装配置是“罐子”):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.acuitus.ldapd.LDAPDaemonImp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
,这里是我的插件配置试图将产生的JAR复制到一个文件夹中的下游项目:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.acuitus</groupId>
<artifactId>ldap-daemon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/classes/www-export</outputDirectory>
<destFileName>ldap-daemon.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
任何援助是非常感谢。谢谢你的时间!
它是一种依赖,而我执行MVN安装,但我可以在下游项目得到的是LDAP守护-0.0.1-SNAPSHOT.jar,不是LDAP守护-0.0.1-SNAPSHOT-JAR-与-dependencies.jar。在上面的第二个插件配置中,我无法找到任何成功的值。我不觉得我需要使用阴影插件,因为我创建的jar是正确的,并且在正确的目录中,但我根本不知道如何在下游项目中引用它。我误解了阴影插件的好处吗?感谢您花时间回答。非常感激! – 2013-05-08 22:42:03
嗨。对不起昨天有点困惑,并没有得到你的要求。我已经更正了上面的答案,并希望这是您正在寻找的内容。 – mszalbach 2013-05-09 08:49:21
完成这项工作:)谢谢!我们最近更改了构建系统,而且我仍然在加快Maven的速度。我感谢您的帮助! – 2013-05-09 18:57:34