Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven uses JRE7 instead of JDK?

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>
like image 263
atripes Avatar asked Nov 06 '12 21:11

atripes


People also ask

Which JDK does Maven use?

Maven Configuration The Maven tool uses JDK version 11.0. 10. The default JDK is set to 13.0.

Does Maven use JAVA_HOME?

Maven always uses the JDK specified by JAVA_HOME , no matter how many JDK installations are available on the system. This allows the user the flexibility to change JDKs as required or based on the project. Hence, it is important to ensure JAVA_HOME is defined.

Does Maven require JDK or JRE?

Maven needs a JDK, and not a JRE. Thanks, Ok yep it is installed.. both JDK and Maven... BUT JAVA_HOME returns Nothing...so still I have some configuration to do to set my JAVA_HOME on OSX ? and without that nothing (EClipse, IntelliJ, etc..)


2 Answers

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")

like image 120
gregwhitaker Avatar answered Oct 03 '22 01:10

gregwhitaker


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.

like image 22
JStark Avatar answered Oct 03 '22 00:10

JStark