2017-06-21 5 views
2

私は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からプロパティを読み取る正しい方法は何ですか(プロファイルをアクティブにしてテストを実行する)?

ありがとうございます。

+0

私は1つのヒントを与えることができます。 Mavenビルドでmaven-ant-runを使用することを考え始める場合は、通常、何か問題があります。その時点で、ここでSOに問い合わせるか、Mavenユーザーのリストに問い合わせてください... https://maven.apache.org/mail-lists.html – khmarbaise

答えて

3

これは難しいことです。

は、プロファイルを取り除くと、発見され、ユニットテストを実行するときに src/main/resourcesのものの前にロードされます src/test/resources/src/test/resources/environment.properties

リソースへsrc/main/resources/environment.test.propertiesからファイルを移動しなさい。

関連する問題