如何使用Maven程序集插件jar-with-dependencies在JAR中包含自定义文件 [英] How to include custom files in JAR with Maven assembly plugin jar-with-dependencies

查看:150
本文介绍了如何使用Maven程序集插件jar-with-dependencies在JAR中包含自定义文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to include custom file (/com/app/log4.properties) in a final JAR.

使用jar-with-dependencies如何将一个文件添加到我的JAR中?

How can I add one file to my JAR when using jar-with-dependencies?

现在,该JAR中只有类文件.我正在使用:

Now there are only class files in that JAR. I'm using:

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>

谢谢.

推荐答案

将非Java文件放入需要在src/main/resources中的最终工件中,在这种情况下:

Put non-Java files that need to be in the final artifact in src/main/resources, in this case:

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

这篇关于如何使用Maven程序集插件jar-with-dependencies在JAR中包含自定义文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆