How to include custom files in JAR with Maven assembly plugin jar-with-dependencies

只谈情不闲聊 提交于 2020-01-15 11:16:26

问题


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

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

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

mvn assembly:assembly

My 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>

Thank you.


回答1:


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


来源:https://stackoverflow.com/questions/15591742/how-to-include-custom-files-in-jar-with-maven-assembly-plugin-jar-with-dependenc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!