开发者

How to run Test unit with VM option

开发者 https://www.devze.com 2023-03-14 12:20 出处:网络
Currently I am doing java project using Maven. There is no problem to run using netbeans or eclips with VM option(-Djava.security.policy=security_policy.txt ) setting in the IDE.

Currently I am doing java project using Maven. There is no problem to run using netbeans or eclips with VM option(-Djava.security.policy=security_policy.txt ) setting in the IDE.

But now i want to run without ECLIPS/NETBEANS and tried mvn test and found this error.

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)

I already experience this prob in Eclips but it is s开发者_如何学Goolved when i put -Djava.security.policy=security_policy.txt in the VM option.

So my question is... How to run using command prompt to include the security option or in short question... how to avoid the AccessControlException ?

Thanks in advance


See systemPropertyVariables (or systemPropertiesFiles), can be set on the Maven test plugin configuration.

Example:

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

This will pass the system property someProperty=someValue to your unit tests.

0

精彩评论

暂无评论...
验证码 换一张
取 消