-
Notifications
You must be signed in to change notification settings - Fork 3
Creating a native executable file for Windows without pre installed java
Download GraalVM from the GraalVM Releases на GitHub. Select a Java version, then unzip the archive.
Then you need to set the variables PATH и JAVA_HOME. Being mindful that there may be multiple JDKs installed on the machine. Open a Windows command prompt and run the following commands.
setx /M PATH “C:\Program Files\<graalvm install dir>\bin;%PATH%”
setx /M JAVA_HOME “C:\Program Files\<graalvm install dir>”
To verify if GraalVM is installed successfully, restart the command prompt and execute command:
java -version
Add Native Image support in GraalVM. GraalVM comes with a package manager, gu, that downloads and installs packages not included in the core distribution.
cd %JAVA_HOME%\bin
gu install native-image
Check for installed features to see if Native Image was added:
gu list
On Windows, for creating Native Image requires Visual Studio Code and Microsoft Visual C++(MSVC).
Download the Visual Studio Build Tools (C development environment) from visualstudio.microsoft.com.
Start the Visual Studio Build Tools installation by clicking on .exe file.
Check the Desktop development with C++ box in the main window. Also, on the right side under «Installation Details», choose Windows 10 SDK, and click the «Install».
Now that you have the Windows 10 SDK and Visual Studio tools installed, you can start using GraalVM Native Image.
On Windows, the native-image builder will only work when it’s executed from the x64 Native Tools Command Prompt.
Use this command if you have the Visual Studio Build Tools installed:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat
Alternatively, you can launch a Dev command prompt from the Visual Studio 2019.
You can then create your own executable file from the command line. Go to the directory where the jar file is located and run the command:
native-image -jar starter.jar starter
Then you can run the executable file:
./starter