gpt4 book ai didi

maven - 如何使用 Maven 程序集插件 jar-with-dependencies 在 JAR 中包含自定义文件

转载 作者:行者123 更新时间:2023-12-05 01:21:37 26 4
gpt4 key购买 nike

我需要在最终的 JAR 中包含自定义文件 (/com/app/log4.properties)。

如何在使用 jar-with-dependencies 时向我的 JAR 添加一个文件?

现在那个 JAR 中只有类文件。我正在使用:

mvn assembly:assembly

我的 pom.xml:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.app.Start</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

谢谢。

最佳答案

将最终 Artifact 中需要的非Java文件放在src/main/resources中,本例中:

src/main/resources/com/app/log4j.properties

关于maven - 如何使用 Maven 程序集插件 jar-with-dependencies 在 JAR 中包含自定义文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15591742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com