2012-11-19 5 views
5
다음 코드와 클래스가 항아리 안에 다음 코드

개미 시험을 자바 시스템 등록 정보를 전달

<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> 

와 함께 항아리를 실행 개미가

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 대상에 지정된 파일에 대해. 내가 잘못하고있는 것이 있습니까? 당신이 독립적 인 실행 환경만을 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"/> 

전에 내가 사용하는 하나

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

4

. junit 타겟은 새로운 환경을 지정합니다 (일부 JVM 스위치를 설정할 때 시스템 속성도 지정해야합니다).

이 시도 :

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

또 다른 대안은 (이클립스에서 외부 실행 구성에서 그 설정 가능) -Dproperties.filename=... 키마다 함께 개미 작업을 실행하는 것입니다. 그러나 단점은 작업을 실행할 때마다 (예 : CI 빌드 또는 새로 체크 아웃 할 때)이 점을 기억해야한다는 것입니다.

+0

아직 널 포인터를 얻었습니다. 어쩌면 스택 추적을 게시해야합니다. – ThaSaleni

+0

빌드 파일에 대한 설정으로 속성을 전달해야합니다. CI 빌드에 대해 자동으로 totaly가되어야합니다. – ThaSaleni

+0

충분히 재미 있습니다./" 내가 을 근무 > 결코 일하지 않았다 – ThaSaleni

관련 문제