私は src/main/java/resources の構造を持つ xyz.jar という jar を持っています。現在、このリソース フォルダーには、 a/fileone.txt b/filetwo.txt と c/filethree.txt という 3 つのサブフォルダーがあります。3 つの異なる war ファイルをビルドするための依存関係として、この jar を使用しています。これらの各 war ファイルでは、3 つのファイルのうちの 1 つだけを使用します。つまり、fileone.txt または filetwo.txt または filethree.txt のいずれかです。3つのwarファイルのいずれかを構築するためのpom.xmlで、残りの2つのファイルを除外するように構成できる方法はありますか? たとえば、firstWar.war をビルドしている場合、fileone.txt のみを含め、他の 2 つを除外します。ここでmaven warプラグインのpackageExcludesを 使用できると思いますが、方法がわかりませんか? ありがとう。
1 に答える
1
- 解決策 1:
リソースを含むjarファイルがあると想定しています。代わりにファイル/リソースを war モジュールに入れて、1 つのビルドから 3 つの異なる war を生成することをお勧めします。これは、maven-assembly-plugin を使用して解決できます。次の構造があります。
.
|-- pom.xml
`-- src
|-- main
| |-- java
| |-- resources
| |-- environment
| | |-- test
| | | `-- database.properties
| | |-- qa
| | | `-- database.properties
| | `-- production
| | `-- database.properties
| `-- webapp
アセンブリ記述子と、もちろん次のような pom ファイルが必要です。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/test.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>qa</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/qa.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>production</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/production.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
記述子ファイルは次のようになります。
<assembly...
<id>test</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<useProjectArtifact>true</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>WEB-INF</outputDirectory>
<directory>${basedir}/src/main/environment/test/</directory>
<includes>
<include>**</include>
</includes>
</fileSet>
</fileSets>
</assembly>
すべてのリソースに必要なもの (あなたの場合は 3 回)。test、qa、production などの環境のように名前を付けることができます (適切な ID を忘れずに付けてください)。これらは src/main/assembly フォルダーに配置する必要があります。または、環境に関連して(file1、file2、file3ですが、実際にはもっと良い名前が存在すると思います)。
- 解決策 2:
使用する jar ファイルに対して同じセットアップを行い、必要なリソースを表す適切な分類子を使用して 3 つの異なる jar ファイルを作成します。ただし、後で war ビルドを変更して、リソースごとに異なる 3 つの war ファイルを作成する必要があります。セットアップについては、ブログ エントリを書きました。
于 2012-04-29T14:55:39.500 に答える