如何在构建期间在jar外创建configs目录

时间:2018-02-26 09:55:24

标签: java maven

我的maven项目中有以下结构

src
 |-main
    |-java
       |-org.my....
          |- ..classes
    |-resources
       |-configs
          |-config1.xml
          |-config2.xml
       |-log4j.xml

我想在构建项目之后在jar之外获取resources/configs目录。也就是说,在我运行mvn clean install之后,我想在target

中看到以下结构
project.jar
configs
  |-config1.xml
  |-config2.xml

我正在使用maven-shade-plugin,我尝试了以下内容,但它没有用。

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>org.mainClass</Main-Class>
                                    <Class-Path>configs</Class-Path>
                                    <!--<resource>src/main/resources/configs</resource>-->
                                    <!--<file>README.txt</file>-->
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>

1 个答案:

答案 0 :(得分:3)

请尝试使用此

https://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html

<outputDirectory>${basedir}/target/extra-resources</outputDirectory>