Reputation: 31
I migrated my project from Java 8 to Java 9. Now when I run maven install on this project inside Intellij Idea it fails with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project tutorial: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jdk-9.0.1..\lib\tools.jar -> [Help 1]
Idea runs the following command:
"C:\Program Files\Java\jdk-9.0.1\bin\java" "-Dmaven.multiModuleProjectDirectory=C:\Users\User\workspace\tutorial" -Dmaven.home=C:\Users\User\install\apache-maven-3.3.9 -Dclassworlds.conf=C:\Users\User\install\apache-maven-3.3.9\bin\m2.conf "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.2\lib\idea_rt.jar=63961:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.2\lib\idea_rt.jar" com.intellij.rt.execution.CommandLineWrapper C:\Users\User\AppData\Local\Temp\idea_classpath org.codehaus.classworlds.Launcher -Didea.version=2017.3.2 -s C:\Users\User\.m2\settings.xml install -DskipTests -P localhost
It works fine if I run mvn install from Windows command line.
All settings point to Java 9:
C:\Users\User>java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
C:\Users\User>echo %JAVA_HOME%
C:\Program Files\Java\jdk-9.0.1
C:\Users\User>echo %JRE_HOME%
C:\Program Files\Java\jre-9.0.1
C:\Users\User>echo %IDEA_JDK%
C:\Program Files\Java\jdk-9.0.1
C:\Users\User>echo %IDEA_JDK_64%
C:\Program Files\Java\jdk-9.0.1
In Idea the following settings all point to Java 9:
Project Structure->Project Settings->Modules->Sources->Language level (Picture)
Project Structure->Project Settings->Modules->Dependencies->Module SDK (Picture)
File->Settings->Build, Execution, Deployment->Build Tools->Maven->Runner->JRE (Picture)
Relevant fragments of my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<testSource>${java.version}</testSource>
<testTarget>${java.version}</testTarget>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<meminitial>${maven-compiler-meminitial}</meminitial>
<maxmem>${maven-compiler-maxmem}</maxmem>
<compilerArgs>
<arg>--add-modules</arg>
<arg>java.xml.bind</arg>
<arg>--add-modules</arg>
<arg>java.se.ee</arg>
</compilerArgs>
</configuration>
</plugin>
<properties>
<java.version>9</java.version>
<maven-compiler-meminitial>512m</maven-compiler-meminitial>
<maven-compiler-maxmem>1024m</maven-compiler-maxmem>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
</properties>
I would be grateful for any tips what could be wrong.
Update
I also noticed, that Idea shows JAVA home as pointing to 1.8 in settings (Picture), while environment variables point to 1.9 (Picture).
Upvotes: 2
Views: 1625
Reputation: 31
In case anyone has similar problem, I was able to fix it by doing the following steps:
Upvotes: 1
Reputation: 137
On startup, intellij determines the JDK in this way. see idea.bat file in the intellij installation directory (bin)
:: Locate a JDK installation directory which will be used to run the IDE. :: Try (in order): IDEA_JDK, idea%BITS%.exe.jdk, ..\jre, JDK_HOME, JAVA_HOME.
Hope this helps
Upvotes: 0