我正在使用 maven 创建一个独立的 java 应用程序,并且我在 jar 文件中使用maven-dependecy-plugin包含依赖项,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>theMainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-my-bundle</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
这包括 lib 文件夹中生成的 jar 文件中的依赖项,并且 jar 运行正常,但问题出在另一个生成的 jar 文件appname-1.0-jar-with-dependencies.jar
中。
问题:我不确定这是否是一个问题,但我注意到在生成的目标文件夹中appname-1.0-jar-with-dependencies.jar
,它包含重复的应用程序文件,例如:
- 所有 sql,property files,xml 文件都存在两次。
- 所有 java 类 .class 文件都存在两次。
- 有很多与依赖项相关的overview.html 和license.txt 文件。
我不确定这是否正确,我也需要有人为我澄清这个生成的 jar 文件的重要性,因为我不熟悉这个插件。
请指教,谢谢。