简体   繁体   中英

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>

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

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.

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.

已安装的JRE

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.

Java执行环境

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.

  • To do that select Run/Run Configurations
  • Select or create the run configuration.
  • Select the Execution Environment tab.
  • Select the appropriate execution environment for this command.

在此输入图像描述

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>

在已安装的JRE首选项窗口中,“转到子菜单执行环境并将此JDK标记为兼容 ”, 如何强制Eclipse m2e插件将jdk用于项目

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM