├── .gitignore ├── LICENSE ├── README.md ├── pom.xml ├── src ├── main │ ├── java │ │ └── de │ │ │ └── jonashackt │ │ │ └── springboot2exe │ │ │ ├── Springboot2exeApplication.java │ │ │ ├── configuration │ │ │ └── SwaggerConfiguration.java │ │ │ └── controller │ │ │ └── Controller.java │ └── resources │ │ └── application.properties └── test │ └── java │ └── de │ └── jonashackt │ └── springboot2exe │ └── Springboot2exeApplicationTests.java └── taskmanager_process_jarlauncher.png /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | executable/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Jonas Hecht 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot2exe - How to package a SpringBoot App with JDKs standard javapackager 2 | 3 | If you ever happen to ask yourself how to package your [Spring Boot](https://projects.spring.io/spring-boot/) App as an .exe File for running in Windows (could that possibly happen :P ?!), then maybe the standard Oracle JDK [javapackager](http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javapackager.html) could be something for you. 4 | 5 | This is a simple example project to show how this is done 6 | 7 | #### 0. Build your Spring Boot App 8 | 9 | Clearly, if you want to package a Spring Boot app, you need one first. Start on [spring initializr](http://start.spring.io/) or simply take this project :) 10 | 11 | 12 | #### 1. Be sure to run all that on a Windows Box! 13 | 14 | It seems to be simple - but all those steps only run on a Windows Machine or VM and will fail on your Mac or Ubuntu :) So fire up one! 15 | 16 | #### 2. You just need a Standard Java-JDK-Installation 17 | 18 | javapackager will be included in your jdk_xxx\bin Folder 19 | 20 | #### 3. Install current Inno Setup release 21 | 22 | All the packaging is done through the freeware [Inno Setup](http://www.jrsoftware.org/isinfo.php) installer for Windows programs - javapackager builds upon it, when creating an exe-File. Get the latest version [here](http://www.jrsoftware.org/isdl.php) and __be sure to have administrative rights!__ Refrain from just installing it on some machine, packaging the resulting Folder under C:\Program Files into a .zip and copy it to another Windows Box -> __This will not work!__ You would get error messages, that are quite confusing like: 23 | 24 | ``` 25 | Bundler EXE Installer skipped because of a configuration problem: Main application jar is missing. javapackager deploy exe 26 | Advice to fix: Make sure to use fx:jar task to create main application jar javapackager 27 | ``` 28 | 29 | ...which will point you in a complete false direction! This is one of the worst error messages I have ever seen :P I just got through to this, by stumbling upon this [blog post](http://code.makery.ch/library/javafx-8-tutorial/part7/)´s comments 30 | 31 | #### 4. do a normal Maven build 32 | 33 | ``` 34 | mvn clean package 35 | ``` 36 | 37 | #### 5. execute javapackager inside your target-Folder, where your Spring boot fat.jar was build 38 | 39 | With our project, the command is something like this: 40 | 41 | ``` 42 | javapackager -deploy -native exe -outdir ./executable -srcfiles springboot2exe-0.0.1-SNAPSHOT.jar -outfile springboot2exe-0.0.1-SNAPSHOT -name springboot2exe-0.0.1-SNAPSHOT -title "Spring Boot 2 .exe" -appclass org.springframework.boot.loader.JarLauncher -v 43 | ``` 44 | 45 | The -appclass __is not your Application.class__ with the main in it! You need to pick Spring Boot´s __org.springframework.boot.loader.JarLauncher__ 46 | 47 | 48 | #### 6. Install target/executable/springboot2exe-0.0.1-SNAPSHOT.exe 49 | 50 | You´ll find a __springboot2exe-0.0.1-SNAPSHOT.exe__ inside your __target/executable/bundles__ folder - install it and it will create a folder inside of __C:\Users\YourUserHere\AppData\Local\JarLauncher__, where the __runtime folder__ holds a JRE and the __app folder__ contains your fat.jar. 51 | 52 | #### 7. Start springboot2exe-0.0.1-SNAPSHOT 53 | 54 | Start __C:\Users\YourUserHere\AppData\Local\JarLauncher\springboot2exe-0.0.1-SNAPSHOT.exe__ - it´s named the same like the installer, but it´s the actual runnable .exe File you wanted. Just take a look inside your Windows Taskmanager: 55 | 56 | ![taskmanager_process_jarlauncher](https://github.com/jonashackt/springboot2exe/blob/master/taskmanager_process_jarlauncher.png) 57 | 58 | 59 | ## More things to do 60 | 61 | #### You need a MacOS DMG? 62 | 63 | javapackager is also capable of packaging DMG Files - read [this post](https://www.igorkromin.net/index.php/2015/07/27/how-to-package-your-java-code-as-a-native-app-on-osx-into-a-dmg-file/) or google it :) -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | de.jonashackt.springboot2exe 7 | springboot2exe 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | springboot2exe 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.1.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 2.6.0 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-devtools 38 | 39 | 40 | 41 | io.springfox 42 | springfox-swagger2 43 | ${springfox.version} 44 | 45 | 46 | 47 | io.springfox 48 | springfox-swagger-ui 49 | ${springfox.version} 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-test 57 | test 58 | 59 | 60 | 61 | com.jayway.restassured 62 | rest-assured 63 | 2.9.0 64 | test 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-maven-plugin 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/main/java/de/jonashackt/springboot2exe/Springboot2exeApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.springboot2exe; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Springboot2exeApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Springboot2exeApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/de/jonashackt/springboot2exe/configuration/SwaggerConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.springboot2exe.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | @Configuration 15 | @EnableSwagger2 16 | public class SwaggerConfiguration { 17 | 18 | @Bean 19 | public Docket api() { 20 | return new Docket(DocumentationType.SWAGGER_2) 21 | .apiInfo(apiInfo()) 22 | .select() 23 | .apis(RequestHandlerSelectors.any()) 24 | .paths(PathSelectors.ant("/springboot2exe/*")) 25 | .build(); 26 | } 27 | 28 | private ApiInfo apiInfo() { 29 | return new ApiInfoBuilder() 30 | .title("Spring Boot to Windows exe") 31 | .description("Simple REST Service just for Demo purposes to show how to create a exe from a Spring Boot app") 32 | .termsOfServiceUrl("http://springfox.io") 33 | .license("Apache License Version 2.0") 34 | .licenseUrl("https://github.com/jonashackt/springboot2exe/blob/master/LICENSE") 35 | .version("2.0") 36 | .build(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/jonashackt/springboot2exe/controller/Controller.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.springboot2exe.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RequestMethod; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | @RequestMapping("/springboot2exe") 9 | public class Controller { 10 | 11 | public static final String RESPONSE = "Hello crazy Windows User!"; 12 | 13 | @RequestMapping(path="/hello", method=RequestMethod.GET) 14 | public String helloWorld() { 15 | System.out.println("Rocking REST!"); 16 | return RESPONSE; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/springboot2exe/e796b18442d4df661cee3a1573a64586e4b2f7c3/src/main/resources/application.properties -------------------------------------------------------------------------------- /src/test/java/de/jonashackt/springboot2exe/Springboot2exeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.springboot2exe; 2 | 3 | import de.jonashackt.springboot2exe.controller.Controller; 4 | import org.apache.http.HttpStatus; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | import static com.jayway.restassured.RestAssured.given; 13 | import static org.junit.Assert.assertEquals; 14 | 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest( 17 | classes = Springboot2exeApplication.class, 18 | webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, 19 | properties = {"server.port=8080"} 20 | ) 21 | public class Springboot2exeApplicationTests { 22 | 23 | @Test 24 | public void testWithSpringRestTemplate() { 25 | // Given 26 | RestTemplate restTemplate = new RestTemplate(); 27 | 28 | // When 29 | String response = restTemplate.getForObject("http://localhost:8080/springboot2exe/hello", String.class); 30 | 31 | // Then 32 | assertEquals(Controller.RESPONSE, response); 33 | } 34 | 35 | /** 36 | * Using Restassured for elegant REST-Testing, see https://github.com/jayway/rest-assured 37 | */ 38 | @Test 39 | public void testWithRestAssured() { 40 | 41 | given() // can be ommited when GET only 42 | .when() // can be ommited when GET only 43 | .get("http://localhost:8080/springboot2exe/hello") 44 | .then() 45 | .statusCode(HttpStatus.SC_OK) 46 | .assertThat() 47 | .equals(Controller.RESPONSE); 48 | } 49 | 50 | @Before 51 | public void setUp() { 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /taskmanager_process_jarlauncher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonashackt/springboot2exe/e796b18442d4df661cee3a1573a64586e4b2f7c3/taskmanager_process_jarlauncher.png --------------------------------------------------------------------------------