【问题标题】:How to run Test unit with VM option如何使用 VM 选项运行测试单元
【发布时间】:2011-06-21 04:57:26
【问题描述】:

目前我正在使用 Maven 做 java 项目。在 IDE 中使用带有 VM 选项(-Djava.security.policy=security_policy.txt)设置的 netbeans 或 eclips 运行没有问题。

但现在我想在没有 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 中遇到过这个问题,但是当我将 -Djava.security.policy=security_policy.txt 放在 VM 选项中时它就解决了。

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

提前致谢

【问题讨论】:

    标签: java maven


    【解决方案1】:

    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 传递给您的单元测试。

    【讨论】:

      猜你喜欢
      • 2019-11-08
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 2020-01-06
      • 2013-11-22
      相关资源
      最近更新 更多