简体   繁体   English

如何在Maven中将文件正确添加到bootclasspath?

[英]How can I add files to the bootclasspath in maven correctly?

I'm using some JSR166 classes with Java 1.6, some of which are under java.util.concurrent . 我在Java 1.6中使用了一些JSR166类,其中一些在java.util.concurrent下。 I am on OSX, though I expect this to ultimately run on Linux. 我在OSX上运行,尽管我希望它最终可以在Linux上运行。

If I set this environment variable I can run my project: 如果设置此环境变量,则可以运行我的项目:

export MAVEN_OPTS=-Xbootclasspath/p:/Users/me/.m2/repository/org/codehaus/jsr166-mirror/jsr166/1.7.0/jsr166-1.7.0.jar

I tried following the instructions here and putting the setting in my pom.xml : 我尝试按照此处的说明进行操作,并将设置放入pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <version>3.0</version>
      <compilerArguments>
        <verbose/>
        <bootclasspath>/Users/me/.m2/repository/org/codehaus/jsr166-mirror/jsr166/1.7.0/jsr166-1.7.0.jar</bootclasspath>
      </compilerArguments>
    </configuration>
</plugin>

Unfortunately this gave an error about not being able to find java.lang . 不幸的是,这给出了关于无法找到java.lang的错误。 If I add a reference to classes.jar (apparently OSX's version of rt.jar ) in the bootclasspath I can fix that error, but that just puts me back where I started: 如果我添加引用classes.jar (显然OSX的版本中rt.jar中) bootclasspath我可以修复的错误,但只是把我带回我开始:

java.lang.SecurityException: Prohibited package name: java.util.concurrent

How should I set up maven to use this argument correctly? 我应该如何设置Maven以正确使用此参数?

You should check security manager. 您应该检查安全经理。 Unfortunately, I don't know specific on OSX. 不幸的是,我不了解OSX的具体信息。 By default, the JVMuses security policies defined in the java.security and java.policy files located under the JAVA_HOME/jre/lib/security folder. 默认情况下,JVM使用在JAVA_HOME / jre / lib / security文件夹下的java.security和java.policy文件中定义的安全策略。 Check also -Djava.security.manager and –Djava.security.policy option for your JVM. 还要检查JVM的-Djava.security.manager和–Djava.security.policy选项。

Shouldn't you use extdir for this, instead of bootclasspath? 您是否应该为此使用extdir而不是bootclasspath?

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <compilerArgs>
            <arg>-verbose</arg>
            <arg>-extdir /Users/me/.m2/repository/org/codehaus/jsr166-mirror/jsr166/1.7.0/</arg>
          </compilerArgs>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

From http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html 来自http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM