On windows, how do I create a standalone .exe executable from a spring-boot project ?
I would like a binary executable that is platform-dependent, and does not rely on an installed JRE. This exec should contain the JRE, all libs/deps (über-jar inside...) and should be able to run on a fresh install of Windows without Java.
I use spring-boot-maven-plugin
in my pom, but mvn package
stops at generating an "executable jar", which still relies on a JRE being installed on the system.
Ideally, the build process would be managed by maven lifecycle, so I tried to use the launch4j-maven-plugin
, but the EXE generated keeps redirecting me to some oracle.com web page.
The app runs fine within IntelliJ "run", JRE 1.8 is in the usual C:Program Files\java
, %JAVA_HOME%
points to JDK 1.16, in C:Program Files\AdoptOpenJDK
Here is the source of my app, single class, console app :
@SpringBootApplication
public class HeyApplication implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(HeyApplication.class, args);
}
@Override
public void run(ApplicationArguments args) {
System.out.println("Hey there !"); // STDOUT
}
}
and an extract from the pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals><goal>launch4j</goal></goals>
<configuration>
<headerType>console</headerType>
<outfile>hey.exe</outfile>
<jar>target/hey-0.0.1-SNAPSHOT.jar</jar>
<errTitle>errr</errTitle>
<classPath>
<mainClass>test.HeyApplication</mainClass>
<addDependencies>true</addDependencies>
<preCp>anything</preCp>
</classPath>
<jre>
<minVersion>1.8</minVersion>
</jre>
<versionInfo>
<fileVersion>1.2.3.4</fileVersion>
<txtFileVersion>txt file version?</txtFileVersion>
<fileDescription>a description</fileDescription>
<copyright>my copyright</copyright>
<productVersion>4.3.2.1</productVersion>
<txtProductVersion>txt product version</txtProductVersion>
<productName>E-N-C-C</productName>
<internalName>ccne</internalName>
<originalFilename>original.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Also, is there, by any chance, a Spring way of doing this JRE wrapping ?