Reputation: 1723
Eclipse Juno Release
Window / Preferences / Java / Installed Jres
shows two installed Jres.
jdk1.7.0_07
and jre7
.
I get the following error when trying to clean
and process-classes
with maven:
Failed to execute goal org.apache.maven.plugins:maven-compiler-
plugin:2.4:compile (default-compile) on project reputation: Fatal
error compiling: tools.jar not found: C:\Program
Files\Java\jre7\..\lib\tools.jar
I added tools.jar
as external jar already, out of desperation, but it didn't help. Why is maven trying to use the other JRE
?
EDIT:
Compiler plugin excerpt from pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Upvotes: 20
Views: 26559
Reputation: 2900
Maven 2.0.9+ supports toolchains that allows you can declare the version of the JDK required for the build.
Excerpt from the related Maven mini-guide:
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.5</version>
<vendor>sun</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
...
</plugins>
Upvotes: 1
Reputation: 5855
To configure maven builds to use the correct java execution environment you need to change the execution environment used by Maven.
1. JRE Locations
To set up JRE locations load the preferences window under Window\Prefences (Windows) or Eclipse\Preferences(OSX) or Edit\Preferences (Linux).
Expand the Java/Installed JREs option Select the JDK of choice, or Add one if not configured.
2. Map Execution Environments
To map any java version to a particular installed JRE select the Java/Installed JREs/Execution environment menu item
Select the appropriate default JRE installation for that version.
3. Run Configurations
If you have particular run configurations, you can change/create specific run configurations and link a specific execution environment just to that command.
Upvotes: 3
Reputation: 12370
In your installed JREs preferences window "go to the submenu Execution Environments and mark this JDK as compatible" from How to force Eclipse m2e plugin to use jdk for a project
Upvotes: 0
Reputation: 2788
You should verify that the Maven "run configurations..." is connected to the correct JRE. If the project JRE is correct but the run configuration JRE is incorrect you will get this error. To fix, go Under Maven Build, choose the JRE tab.
Upvotes: 8
Reputation: 13420
You need to set your JAVA_HOME environment variable to the JDK directory.
EDIT:
In your installed JREs preferences window in Eclipse remove the JRE and select the JDK. Also make sure that your project is set to use that JRE library (Right-click on the "JRE System Library" under your maven project structure in the explorer and set it as the "Execution Environment")
Upvotes: 25