私はJava Webアプリケーション(No Spring)を開発しています。プロダクション用とテスト用に別々のdbを使用したいと思います。src/main/resourcesに2つのファイルがあります - env.propertiesとenv.test.properties 。 私はhttps://maven.apache.org/guides/mini/guide-building-for-different-environments.htmlで述べたように、pom.xmlにプロファイルを定義しました。Mavenプロファイルテスト用
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete file="${project.build.outputDirectory}/environment.properties"/>
<copy file="src/main/resources/environment.test.properties"
tofile="${project.build.outputDirectory}/environment.properties"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>test</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
しかし、私は-Ptest Mavenのテストでテストを実行したとき、私は私のテストはenv.propertiesからデシベルで実行し、テストの完了後に取得されていることが分かり、プロファイルの切り替えが起こります。 私はテストとデプロイを構築するjebkinsパイプラインも持っています。 ここに何か不足していますか? env.test.propertiesからプロパティを読み取る正しい方法は何ですか(プロファイルをアクティブにしてテストを実行する)?
ありがとうございます。
私は1つのヒントを与えることができます。 Mavenビルドでmaven-ant-runを使用することを考え始める場合は、通常、何か問題があります。その時点で、ここでSOに問い合わせるか、Mavenユーザーのリストに問い合わせてください... https://maven.apache.org/mail-lists.html – khmarbaise