【问题标题】:How to include custom files in JAR with Maven assembly plugin jar-with-dependencies如何使用 Maven 程序集插件 jar-with-dependencies 在 JAR 中包含自定义文件
【发布时间】:2013-03-13 13:44:52
【问题描述】:

我需要在最终的 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>

谢谢。

【问题讨论】:

    标签: maven pom.xml maven-assembly-plugin


    【解决方案1】:

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

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

    【讨论】:

    • 如果文件位于文件系统中的某处怎么办?
    • @Enerccio 万一呢?然后您将 log4j 设置为使用外部配置文件。
    • 我正在尝试透明地包含来自 jdk 的 jar 并且没有大惊小怪
    • @Enerccio 这似乎是一个完全不相关的问题;也许搜索或发布一个新的。但如果它来自 JDK,则不需要这样做。
    猜你喜欢
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    相关资源
    最近更新 更多