質問

コマンドラインを使用して、システムプロパティをJavaに渡します。 Linuxボックスで Hudson ビルドを実行しているときの仮想マシン。使った 2.1.0にアップグレードしてから2.0.9で非常にうまく機能するようになりました 完全に動作を停止しました。システムプロパティは決してそれを作りません Java仮想マシンに。

小さなテストプロジェクトを作成しましたが、実際にはまったく機能しません。

これは、 Maven 2.0.9で問題なく動作するはずです:

mvn2.0.9 -Dsystem.test.property=test test 

ただし、これは失敗します:

mvn2.1 -Dsystem.test.property=test test 

Javaコードは単にこれを行います

assertTrue( System.getProperty("system.test.property") != null); 
役に立ちましたか?

解決

これはMavenまたはSurefireプラグインの問題ではないと思います。それ以外の場合、確実な動作は異なります。 Surefireが JVM をフォークすると、親からすべてのシステムプロパティを取得しないようになりましたJVM。

だからこそ、argLineを使用して、テストに必要なシステムプロパティを渡す必要があります。 したがって、これらは両方とも動作するはずです

mvn2.1 -Dsystem.test.property=test test -DforkMode=never 

または

mvn2.1 test -DargLine="-Dsystem.test.property=test"

他のヒント

Surefire プラグインでこれを経験しました。 Surefireプラグインは、Mavenによって起動される別のJVMインスタンスの下で実行されます。コマンドラインパラメーターは、pom.xmlのsurefile-plugin構成で構成できます。以下に設定のサンプルを示します。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.3</version>
            <!--
                    By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
                    "**/Test*.java" - includes all of its subdirectory and all java filenames that start with "Test". "**/*Test.java" -
                    includes all of its subdirectory and all java filenames that end with "Test". "**/*TestCase.java" - includes all of
                    its subdirectory and all java filenames that end with "TestCase".
                -->
            <configuration>
                <includes>
                    <include>**/*Test.java</include>
                </includes>
                <systemProperties>
                    <property>
                        <name>app.env</name>
                        <value>dev</value>
                    </property>
                     <property>
                        <name>oracle.net.tns_admin</name>
                        <value>${oracle.net.tns_admin}</value>
                    </property>
                </systemProperties>
            </configuration>
        </plugin>

設定ファイルとコマンドライン引数を混同しないように注意してください。構成ファイル(pom.xml)は、すべてのcmd引数をオーバーライドしています。したがって、raisercostinの説明のようにコマンドラインで渡す場合は、pom.xml内でsurefireプラグインを設定しないでください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top