【问题标题】:Move resource files to target and exclude from jar将资源文件移动到目标并从 jar 中排除
【发布时间】:2016-09-26 14:48:31
【问题描述】:

我有一个这样的 Maven 项目:

\src
   \--main
      \--java
         \--fu
            \--bar
               \--AppMain.java
      \--resources
         \--log4j.xml

通过 pom 使用 maven-resources-plugin 将我的资源文件移动到目标目录,如下所示:

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>my/target/dir/config</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

还有 maven-jar-plugin 像这样创建 jar:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>fu.bar.AppMain</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

当我运行mvn clean install 时,我的目标位置包括已编译的jar 和\config\log4j.xml。但是,jar 还包含log4j.xml

如何从 jar 中排除 log4j.xml 并仍将其移动到 \my\target\dir\config

【问题讨论】:

    标签: maven maven-resources-plugin


    【解决方案1】:

    将这个添加到我的 pom 中是诀窍:

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
    </build>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 2016-06-20
      相关资源
      最近更新 更多