Maven では、maven-resources-plugin
プラグインを使用して src/main/resources ディレクトリ内のリソース ファイルを分離し、独立したリソース ファイル パッケージを生成できます。
プラグインを使用するにはmaven-resources-plugin
、まずプロジェクトの pom.xml ファイルに次の構成を追加する必要があります。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/resources</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
上記の構成は、 Maven フェーズでゴールpackage
を実行しcopy-resources
、src/main/resources ディレクトリ内のすべてのファイルを${project.build.directory}/resources
そのディレクトリにコピーします。
mvn package
コマンドを実行すると、src/main/resources ディレクトリ内のすべてのファイルを含む独立したリソース ファイル パッケージが生成されます。${project.build.directory}/resources
このリソース ファイル パッケージはディレクトリにあります。
これはリソース ファイルを個別に分離する単なる方法であり、実際のアプリケーションの特定のニーズに応じて調整する必要がある場合があることに注意してください。