Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mvn compile: Unable to find package java.lang

Tags:

java

maven

I have maven-compiler-plugin settings below:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <compilerArguments>
            <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
        </compilerArguments>
    </configuration>
</plugin>

When executing mvn compile, it reports Unable to find package java.lang in classpath or bootclasspath. But I do find java.lang package in /Library/Java/JavaVirtualMachines/jdk1.8/Contents/Home/jre/lib/rt.jar:

java/lang/Thread$UncaughtExceptionHandler.class
java/lang/ThreadGroup.class
java/lang/Runnable.class
java/lang/Thread.class
java/lang/ref/Finalizer.class
java/lang/ref/PhantomReference.class
java/lang/ref/FinalReference.class
java/lang/ref/WeakReference.class
java/lang/ref/SoftReference.class
java/lang/ref/Reference.class
......

I'm using Oracle JDK 1.8 on OS X 10.11.3. What extra info should I provide? Is the problem from JDK or project's maven setting?

edit:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8/Contents/Home

edit2:

Different from Maven : unable to find java.lang issue on OS X, I'm using Oracle JDK

edit3:

maven version

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.3", arch: "x86_64", family: "mac"

/Library/Java/JavaVirtualMachines/jdk1.8/Contents/Home is a soft link to /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home shown in maven version info

like image 240
hbprotoss Avatar asked Mar 01 '16 05:03

hbprotoss


1 Answers

<compilerArguments> is deprecated, but that's not why it's not working. These types of arguments only work if <fork> is set to true.

This works for me:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
     <source>1.8</source>
     <target>1.8</target>
     <fork>true</fork>
     <compilerArgs>
       <arg>-bootclasspath</arg>
       <arg>${java.home}/lib/rt.jar${path.separator}${java.home}/lib/jce.jar</arg>
     </compilerArgs>
  </configuration>
</plugin>
like image 183
Daniel Avatar answered Sep 30 '22 06:09

Daniel