将java系统属性传递给ant测试
我有ant使用以下代码执行jar
在jar里面有一个包含以下代码的类
public static MyFacade createFacade() throws FileNotFoundException, IOException { return createFacade(System.getProperty(properties.filename)); }
然后有一个配置为这样的ant测试目标
我在此测试目标模块中的测试无法获取我在start.my.jar目标上指定的文件的属性。 有什么我做错了吗?
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.(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.(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)
那是因为你只为java
目标添加了属性,这是一个独立的运行时环境。 junit
目标指定一个新环境(当你为它设置一些JVM开关时,你也需要指定系统属性)。
尝试这个:
....
另一种方法是每次都使用-Dproperties.filename=...
键运行ant任务(您可以在Eclipse中的外部运行配置中设置它)。 但是,缺点是,每次要运行任务时都必须记住这一点(例如,在CI构建中或使用新的签出)。
有趣的是这个工作:
我以前用过的那个:
从未工作过