2011-06-21 38 views
1

目前我正在使用Maven做java项目。在IDE中运行使用netbeans或eclip与VM选项(-Djava.security.policy = security_policy.txt)设置没有任何问题。如何运行虚拟机测试单元选项

但现在我想运行没有ECLIPS/NETBEANS,并试图mvn test,发现这个错误。

java.security.AccessControlException: access denied (java.io.FilePermission D:\Tecforte\LR4\branches\Prototype\LR_V4\Collector\.\config\logging.proper 
ties read) 
     at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323) 
     at java.security.AccessController.checkPermission(AccessController.java:546) 
     at java.lang.SecurityManager.checkPermission(SecurityManager.java:532) 
     at java.lang.SecurityManager.checkRead(SecurityManager.java:871) 

我已经遇到此概率在ECLIPS但它解决了,当我在VM选项把-Djava.security.policy=security_policy.txt

所以我的问题是...如何运行使用命令提示符包括安全选项或简短的问题...如何避免AccessControlException?

预先感谢

回答

2

参见systemPropertyVariables(或systemPropertiesFiles),可以在Maven的测试插件配置进行设置。

实施例:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.9</version> 
    <configuration> 
     <systemPropertyVariables> 
      <someProperty>someValue</someProperty> 
     </systemPropertyVariables> 
    </configuration> 
</plugin> 

这将系统属性someProperty = someValue中传递到您的单元测试。