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

4.4k Views Asked by At

I'm using some JSR166 classes with Java 1.6, some of which are under java.util.concurrent. I am on OSX, though I expect this to ultimately run on 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:

<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. 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:

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

How should I set up maven to use this argument correctly?

2

There are 2 best solutions below

0
On

Shouldn't you use extdir for this, instead of 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

0
On

You should check security manager. Unfortunately, I don't know specific on 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. Check also -Djava.security.manager and –Djava.security.policy option for your JVM.