Mvn compile: Cannot find java.lang package

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 the mvn compile it reports Unable to find package java.lang in classpath or bootclasspath . But I find the 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 am using Oracle JDK 1.8 for OS X 10.11.3. What additional information should I provide? Is the problem related to setting up a JDK or maven project?

edit:

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

edit2:

Unlike Maven: could not find java.lang problem in OS X , I use 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 specified in the maven version information

+5
source share
1 answer

<compilerArguments> deprecated, but not because it does not work. These argument types work only if the <fork> parameter 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> 
+4
source

Source: https://habr.com/ru/post/1244172/


All Articles