weird problem with JAVA_HOME and maven dependencies

余生颓废 提交于 2019-12-03 05:27:39
moritz

You will need a Java JDK not just a JRE. You can get one at Oracle's Java Page

Edit: From the Maven Properties Guide:

${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
<jvm>${java.home}../bin/java.exe</jvm>

And with a JDK for example in c:\jdk the maven ${java.home} is pointing to c:\jdk\jre

I also found this that helped me out.

... With Eclipse, you need to verify that Installed JREs are using JDK installs.

This means that in the configuration option... Window / Preferences / Java / Installed JREs ...You should point to a JDK installation.

You need to change the path to the jre within the jdk. for %Program Files%\Java\jdk1.6.0_25\jre

The java.home variable can be further derived from your project pom.xml. Double-Check your maven compiler-plugin reference. I had this same problem, when trying to build, about it whining it cannot find javac. My java.home, JAVA_HOME were all set correctly.

What turned out to be FIX for me was correcting the pom.xml I ended up making the following changes:

            <!-- Original Version of compiler plugin reference -->
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>${default.java.version}</source>
                <target>${default.java.version}</target>
                <showDeprecation>false</showDeprecation>
                <executable>${default.java.home}/bin/javac</executable>
                <compilerVersion>${default.java.version}</compilerVersion>
                <fork>true</fork>
            </configuration>

            <!-- MODIFIED Version of compiler plugin reference -->
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>

                <!-- SPECIFY A DISCRETE VERSION!! Do not let it derive it! -->
                <source>1.6</source>
                <target>1.6</target>

                <!--
                  <showDeprecation>false</showDeprecation>
                  <executable>${default.java.home}/bin/javac</executable>
                  <compilerVersion>${default.java.version}</compilerVersion>
                  <fork>true</fork>
               -->
            </configuration>

This issue also crops up in Intellij IDEA (IDEA 11.x ~ Windows 7 ~ Java 7). Specifying the systempath property was referencing the IDEA jre ...

A stable solution was to create a local maven profile under $HOME/.m2/settings.xml

<profiles>
  <profile>
    <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
          <jdk>NUMERIC_VERSION</jdk>
        </activation>
        <properties>
          <java.home>                   
            <!-- ABSOLUTE_PATH_HERE -->
          </java.home> 
        </properties>
  </profile>
</profiles>
user2071961

Just to add a little more information to the answer about changing Window preferences. I had put the JRE location as C:\Program Files\Java\jre7 because this seemed the obvious choice.

However, this is a fail. The correct answer as pointed out is C:\Program Files\Java\jdk1.7.0_10\jre. I'm pointing this out because its an easy mistake to make.

Had the same issue today. Turns out I specifically needed to use "Program Files" in the path, despite this windows install (and thus the folder's name) being in German.

It's not the first time this sort of thing happened, either.

So if you're sure your paths are correct, try "Program Files" instead of your localized alternative. Worked for me.

to write, compile and package java program's a JDK is needed, because the necessary tools are only distributed with a JDK (Java Development Kit). The JRE (Java Runtime Environment) is only needed to run a java program.

Without messing with the JAVA_HOME env variable, here is how I was able to fix it.

Install the 1.6.x jdk.

In Eclipse/Preferences under installed JREs, add an entry for the JDK and make it the default (set the location to the JDK folder, eg., C:\Program Files\Java\jdk1.6.0_34

Edit the properties and add JDK_HOME/lib/tools.jar to the system libraries list.

Alternately, assuming the jdk is installed, you can add the JDK/lib/tools.jar to the system libraries list of your existing default JRE

kumara balaji

I was able to see the appropriate response in command prompt while keying in java -version but got this error while typing mvn -version.

In my case, it was a silly mistake. JAVA_HOME environment variable was pointing to the ..\jdk\bin folder all these days and that caused the problem. After removing the bin from the JAVA_HOME variable's value, I could able to work with Maven.

Note: System variable path should contain the value that points to the bin folder of your JDK.

Regards, Balaji.K

Proper way to configure JAVA environment variables is :-

  1. Set JAVA_HOME to Your "jdk folder"\jre
  2. Add "jdk folder"\bin to Your PATH user environment variable

JAVA_HOME is location of "java.exe" which needs to come from JRE\bin folder. PATH is to look for javac.exe which needs to come from JDK\bin folder.

This also ensures JDK and JRE are compatible

For Maven to run - You need to configure an environment variable JAVA_HOME to point to a JDK

e.g. JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25

Also you need the C:\Program Files\Java\jdk1.7.0_25\bin included in the PATH environment variable.

Regards, Dipan

Naveen

I have faced similar issue , the following resolved the issue:

JAVA_HOME = C:\Program Files\java\jdk
M2_HOME= C:\Program Files\apache-maven

inside path = ....%JAVA_HOME%\bin;%M2_HOME%\bin;

this solved the issue.

i had a similar Problem and the answer is that easy;

maven couldn´t find the JAVA_HOME varaiable, until i realized, that i wrote the Java path into my path-variable. So the answer to my "ERROR: JAVA_HOME not found in you Environment..." was to create a new variable with Name JAVA_HOME. Maybe thats a failure for dummies but it took me one hour to realize ...

You should also make sure Java library is on your project's classpath. Navigate to project's properties->java build path->libraries tab. Check if jdk library is listed out. If not add it. This can also be the cause of such error.

I just had this problem after a Java auto-update (on Windows 7) for my command line Maven projects (separate issue than the maven version within Eclipse). The JRE auto-update removed the jre folder under the JDK that was pointed to by my system JAVA_HOME environment variable. Since the jre wasn't found, maven was defaulting to the newly installed JRE (still haven't figured out how). I restored the jre folder under my JDK directory and removing a reference to C:\ProgramData\Oracle\Java\javapath which had been added to the start of the system Path variable, and the maven builds returned to normal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!