How to fix maven error JAVA_HOME environment variable not defined correctly?

Problem:

I get the Maven error "JAVA_HOME environment variable is not defined correctly" when I start Inno batch execution. However, I can successfully work outside of Inno Setup (e.g. Command line, Batch file, Vbs). I do not know how to do that.

Inno Setup Invoked Prompt:

C:\>mvn -version The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK not a JRE 

Regular command line:

 C:\>mvn -version C:\ Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T01:09:06+05:30) Maven home: C:\Program Files\apache-maven-3.5.0\bin\.. Java version: 1.8.0_131, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_131\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows" 

Maven Team from InnoSetup:

 [Files] Source: "C:\@Setup\MavenInstaller.bat"; DestDir: "{tmp}"; Flags: ignoreversion [Run] Filename: "{cmd}"; Parameters: "/C ""{tmp}\MavenInstaller.bat""" 

Maven command from a batch file:

 mvn archetype:generate -DgroupId=com.mycompany.mycomponent-DartifactId=%APPLICATION_NAME% -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false 

JAVA_HOME setting

Check if Java 1.8 is installed or not. If it is not installed, install it and install JAVA HOME as follows.

 SETX JAVA_HOME "C:\Program Files\Java\jdk1.8.0_131" SETX -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0_131" REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_SZ /d "%path%;C:\Program Files\Java\jdk1.8.0_131\bin;" /f 

Thank you very much.

+18
source share
14 answers

The SETX command SETX not change the current environment.

If you run the following batch file:

 setx AAA aaa echo AAA=%AAA% 

He will print

 AAA= 

So your batch file is wrong. You should use set :

 set AAA=aaa 

See What is the difference between SETX and SET in Windows environment variables.

+3
source

My JDK is installed on C:\Program Files\Java\jdk1.8.0_144\ .
I set JAVA_HOME= C:\Program Files\Java\jdk1.8.0_144\ and I was getting this error:

 The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK not a JRE 

When I changed the JAVA_HOME value to C:\Program Files\Java\jdk1.8.0_144\jre , the problem was fixed.
I'm not sure how.

+25
source

The following is the best way to solve the problem, check the following on the classpath:

  1. Make sure that the JAVA_HOME system variable must be set to jdk, for example C:\Program Files\Java\jdk1.7.0_80 , not C:\Program Files\Java\jdk1.7.0_80 here bin.

  2. Because MAVEN will search for jre, which is in C:\Program Files\Java\jdk1.7.0_80

  3. Set %JAVA_HOME%\bin in the classpath.

Then try the Maven version.

Hope this helps.

+10
source

I deleted the JAVA_HOME variable and saved only the path and classpath variables, pointing them to jdk and jre respectively. It worked for me.

+4
source

I encountered the same problem when using the mvn clean package command on windows

 C:\eclipse_workspace\my-sparkapp>mvn clean package The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK not a JRE 

I solved this problem by removing the JAVA_HOME environment variables from user variables / system variables, then restarted the laptop, and then set the JAVA_HOME environment variable again.

Hope this helps you.

+3
source

I had the same problem when my JAVA_HOME system variable was pointing to C: \ Program Files \ Java \ jdk1.8.0_171 \ bin and my PATH entry consisted of% JAVA_HOME%.

I changed my JAVA_HOME variable to exclude the bin folder (C: \ Program Files \ Java \ jdk1.8.0_171), and added the bin folder to the PATH system variable:% JAVA_HOME% \ bin,

+3
source

Setting the JAVA_HOME directory from the command line worked for me!

First:

 JAVA_HOME="C:\Program Files\Java\jdk1.8.0" 

Or:

 export JAVA_HOME="C:\Program Files\Java\jdk1.8.0" 

Then try:

 mvn -version 

to make sure you do not get the same error. :)

+2
source

I was struggling with the same problem and the following worked for me.

Step 1: Check your JAVA_HOME settings. It might look something like this:

 JAVA_HOME="/usr/libexec/java_home" 

Step 2: Update JAVA_HOME as follows:

 $ vim .bash_profile export JAVA_HOME=$(/usr/libexec/java_home) $ source .bash_profile 

Step 3: In the new shell, verify that the Maven command now works correctly:

 $ mvn -version 

If this solves the problem, you should get an answer like:

 Apache Maven 3.0.3 (r1075438; 2011-03-01 01:31:09+0800) Maven home: /usr/share/maven Java version: 1.7.0_05, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.8.2", arch: "x86_64", family: "mac" 
+1
source

I had the same issue on Windows 7.

 The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK not a JRE 

The solution turned out to be very simple - right-click on the command line shortcut and select "Run as administrator". After that, the problem disappeared)

0
source

If all the good and still-standing "JAVA_HOME" should point to a JDK problem, not a JRE, "check the java config user variables and the java config system variables once. This solved my problem.

0
source

In the case of windows, if there is a space in the jdk path (for example, "C: \ Program Files \ jdk"), it does not work, but if we save jdk in a place where there is no place, it works fine. like ("C: \ JDK")

0
source

This worked for me for Windows 10, Java 8_144.

If the path contains spaces, use the abbreviated path name. For example, C: \ Progra ~ 1 \ Java \ jdk1.8.0_65

0
source

A very common mistake people make is that when they install JAVA_HOME or JRE_HOME , they set the value to C:\Program Files\Java\jdk1.8.0_221\bin or the like.

Please note that JAVA_HOME and JRE_HOME must not contain \bin

0
source

I have a problem below: C: \ Program Files \ SolarWinds \ DPA \ iwc \ tomcat \ bin> startup.bat JAVA_OPTS has the value -server -Xss256k -Xms256m -Xmx1024m -Dnet.sf.ehcache.skipUpdateCheck = true -Dorg.apache .commons.logging.LogFactory = org.apache.commons.logging.impl.LogFactoryImpl Neither the JAVA_HOME environment variable nor the JRE_HOME variable are defined. At least one of these environment variables is required to run this program.

this is me running in Solarwinds when I run Java

anyone help check?

0
source

Source: https://habr.com/ru/post/1269070/


All Articles