Issue
Issue:
I am getting the Maven error "The JAVA_HOME environment variable is not defined correctly" when I run through Inno setup batch execution. However, I am able to run successfully outside Inno Setup.(e.g Command line, Batch file, Vbs). I am clueless to identify the issue.
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 Prompt:
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 Command from InnoSetup:
[Files]
Source: "C:\@Setup\MavenInstaller.bat"; DestDir: "{tmp}"; Flags: ignoreversion
[Run]
Filename: "{cmd}"; Parameters: "/C ""{tmp}\MavenInstaller.bat"""
Maven Command from Batch File:
mvn archetype:generate -DgroupId=com.mycompany.mycomponent-DartifactId=%APPLICATION_NAME% -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Setting JAVA_HOME
Check the If Java 1.8 is installed or not. If not installed, Install the same and set the 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
Many Thanks.
Solution
The SETX
command does not modify the current environment.
If you run the following batch file:
setx AAA aaa
echo AAA=%AAA%
It will print
AAA=
So your batch file is wrong. You have to use set
:
set AAA=aaa
See What is the difference between SETX and SET in environment variables in Windows.
Answered By - Martin Prikryl
Answer Checked By - Katrina (JavaFixing Volunteer)