2012-11-19 12 views
5
Iは、次のコードでクラスがあるジャー内部次のコード

ANT試験にJavaシステムプロパティを渡す

<target name="start.my.jar" description="start my jar"> 
    <echo message="Starting the jar" /> 
    <java jar="${jars.dir}/${my.stub.jar}" fork="true" dir="${jars.dir}" spawn="true"> 
      <sysproperty key="properties.filename" value="${basedir}/path/path/path/filename.properties"/> 
     <arg value="start" /> 
    </java> 
</target> 

でジャーを実行するANT有する

public static MyFacade createFacade() throws FileNotFoundException, IOException { 
    return createFacade(System.getProperty(properties.filename)); 
}  

、次いで、アリがありますこのように設定されたテスト目標

<target name="test" depends="compile, support" description="perform unit tests"> 
    <mkdir dir="${build.test}" /> 
    <mkdir dir="${test-classes.dir}" /> 
    <javac srcdir="${build.test}" destdir="${test-classes.dir}" debug="${debug}" nowarn="${nowarn}" includeantruntime="false" deprecation="${deprecation}"> 
     <classpath refid="main.classpath" /> 
    </javac> 
    <junit printsummary="yes" haltonfailure="yes" showoutput="true" dir="${test-classes.dir}" fork="true" forkmode="perBatch" failureproperty="junit.failure" errorproperty="junit.error" haltonerror="no"> 
     <jvmarg value="-Xmx1G" /> 
     <jvmarg value="-Dcom.sun.management.jmxremote" /> 

     <classpath> 
      <pathelement location="${test-classes.dir}" /> 
      <pathelement location="${classes.dir}" /> 
      <!-- 
      For module restful_api 
      --> 
      <pathelement location="${build.deploy}" /> 
      <pathelement location="${classes.dir}" /> 
      <fileset dir="${build.lib}"> 
       <include name="*.jar" /> 
      </fileset> 
     </classpath> 
     <formatter type="plain" /> 
     <batchtest fork="yes" todir="${build.test}"> 
      <fileset dir="${build.test}"> 
       <include name="**/*AllTests.java" /> 
       <include name="**/*TestCase.java" /> 
      </fileset> 
     </batchtest> 
    </junit> 
    <fail message="Unittest failures - please check" if="junit.failure" /> 
    <fail message="Unittest errors - please check" if="junit.error" /> 
</target> 

このテスト対象モジュールでのテストでは、プロパティを取得できませんstart.my.jarターゲットで指定されたファイルiの場合私が間違っていることは何ですか?あなたは独立した実行環境であるだけjavaターゲット、のプロパティを追加するためです

SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container 
[junit] java.lang.NullPointerException 
[junit]  at java.io.File.<init>(File.java:222) 
[junit]  at com.mycompany.myproduct.sdk.facade.MyFacadeFactory.getInputStream(MyFacadeFactory.java:47) 
[junit]  at com.mycompany.myproduct.sdk.facade.MyFacadeFactory.loadFacade(MyFacadeFactory.java:43) 
[junit]  at com.mycompany.myproduct.sdk.facade.MyFacadeFactory.createFacade(MyFacadeFactory.java:32) 
[junit]  at com.mycompany.myproduct.sdk.facade.MyFacadeFactory.createFacade(MyFacadeFactory.java:28) 
[junit]  at com.mycompany.myproduct.sdk.resources.impl.TransactionResourceImpl.<init>(TransactionResourceImpl.java:70) 
[junit]  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
[junit]  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
[junit]  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
[junit]  at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
[junit]  at com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:191) 
+1

がでcreateFacade(はSystem.getProperty( "properties.filenameを"))を返してみ働いたことはありません。 – user1097489

+0

私は実際にはproperties.filenameですが、まだ動作していない間違いをしました – ThaSaleni

+0

stacktraceを投稿できますか? – user1097489

答えて

1

おかしいは十分にこれが働いた:

<jvmarg value="- Dproperties.filename=${basedir}/path/path/path/filename.properties"/> 

前に私が使用した1:

<sysproperty key="" value=""/> 

4

junitターゲットで新しい環境が指定されています(JVMスイッチを設定するときには、システムプロパティも指定する必要があります)。

これを試してみてください:

<junit ...> 
    <sysproperty key="properties.filename" 
      value="${basedir}/path/path/path/filename.properties"/> 
    .... 
</junit> 

別の方法(あなたはEclipseの外部の実行構成にそれを設定することができます)-Dproperties.filename=...キーで毎回Antタスクを実行することです。しかし、欠点は、タスクを実行するたびに(CIビルドや新しくチェックアウトして)これを覚えておく必要があることです。

+0

私はまだ、nullポインタを取得して...多分私はまた、スタックトレースを投稿する必要があります – ThaSaleni

+0

私はビルドファイルに設定としてプロパティとして渡す必要があるので、私はtotaly CIビルドのために自動する必要がある – ThaSaleni

+0

面白い > 決して働かなかった – ThaSaleni