Maven:属性文件和jar一起

Ale*_*lec 6 jar maven-plugin maven-3 maven properties-file

我将我的应用程序打包为jar.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>...</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

而且我的.properties文件放在里面src/main/resources.我可以随意将此文件移动到任何其他地方.我不希望将属性文件包含在jar中,而是放在同一个输出目录(我们得到jar的地方)并排放置.在Maven中最好的做法是什么?

Ale*_*lec 9

好了,可以使用目标资源:复制资源Maven的资源插件.我刚刚离开标准资源文件夹嵌入(进入jar)资源.对于外部资源,我创建了另一个文件夹:src/main/external-resources.在这里,我把我的.properties文件.

以下部分将在验证阶段将外部资源复制到输出目录.您可以根据自己的需要更改阶段.

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/external-resources</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)