Packaging a Spring Boot application as Windows exe

I programmed once this handy tool to retrieve one-time passwords (too much insider knowledge for opensourcing it) and as soon as some teammates heard about it, they asked for a copy to spare them the zillion clicks the password generator needs. But… the tool existed only as a Maven project in my development environment 😦

It makes no sense to torture my dear business analyst mate with a maven installation, so I thought I’d package the JAR in a Windows EXE so it can be run at will. Launch4j is doing exactly that: you get a handy GUI tool (not exactly intuitive) which in the end creates an exe. Some great folks even created a Maven plugin for this Launch4j!

It’s just… every time I created the EXE from the GUI tool it worked, and every time I created it from Maven it failed.

I even saved the GUI configuration and reproduced it in Maven, to no avail. Then it came to me – I should need to specify the Spring Boot main class, not my application’s! And lo, it worked as a charm! Below is the proper Maven configuration, have fun 🙂

 <plugin>
   <groupId>com.akathist.maven.plugins.launch4j</groupId>
   <artifactId>launch4j-maven-plugin</artifactId>
   <version>1.7.21</version>
   <executions>
     <execution>
       <id>l4j-pampass</id>
       <phase>package</phase>
       <goals>
         <goal>launch4j</goal>
       </goals>
       <configuration>
         <headerType>console</headerType>
         <jar>${project.build.directory}/${project.build.finalName}.${project.packaging}</jar>
         <outfile>${project.build.directory}/${project.build.finalName}.exe</outfile>
         <downloadUrl>http://java.com/download</downloadUrl>
         <classPath>
           <mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
         </classPath>
         <jre>
           <path>${java.home}</path>
           <bundledJre64Bit>true</bundledJre64Bit>
           <runtimeBits>64</runtimeBits>
         </jre>
       </configuration>
     </execution>
   </executions>
 </plugin>

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s