我一直在研究最终创建可执行 jar 文件的 Java Maven 项目。起初我没有任何问题,但后来我决定我希望将依赖项也复制到 jar 中。
我发现了以下(非常有用的)堆栈溢出问题,并按照答案中提供的说明进行操作(替换我自己的主类和目标版本):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-daemon-0.0.1-SNAPSHOT.jar 包含它的依赖项
- 使用 maven-dependency-plugin 复制第二个构建工件 (ldap-daemon-0.0.1-SNAPSHOT-jar-with-dependencies.jar)。
这是我的 ldap-daemon 插件配置(打包配置是“jar”):
<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>
非常感谢任何帮助。谢谢你的时间!