4

Is there a way to bundle a spring-boot application into one executable jar including a JRE?

I think I saw someone doing that (Josh Long?) which resulted in a jar you could start via java -jar foo.jar and even with ./foo.jar

I googled for this the last hour but couldn't find any documentation on this, anyone there to help me out?

EDIT:

I just found what I saw at the conference. spring-boot 1.3 introduces something called executable jars, which wrap the jar with a shell script. Enabling this makes it possible to run your jar like ./my.jar and tying it to an unix init system. However, you still need java installed at your host.

Enabling this feature in gradle is as easy as adding this to your build.gradle

springBoot {
    executable = true
}
Marged
  • 10,577
  • 10
  • 57
  • 99
hennr
  • 2,632
  • 2
  • 23
  • 26
  • 1
    what you are trying to do is a chicken-and-the-egg problem. If the JAR contains the JRE how do you want to run the JAR ? Which operating system is this supposed to run on ? What you probably are searching for is a installer for Java programs. Have a look here: http://stackoverflow.com/questions/184060/java-application-installers – Marged Sep 23 '15 at 19:21
  • So we are talking about a linux solution. This seems to be the same trick that Oracle uses for its Java installers or what they do here: http://www.linuxjournal.com/content/add-binary-payload-your-shell-scripts – Marged Sep 23 '15 at 19:35

2 Answers2

2

Propably you are using Maven. This maven plugin allows you to create single jar file with all dependencies. Next you can use tool such as jwrapper which allows to build executable file with embeded JRE for many platforms.

borysfan
  • 182
  • 1
  • 6
2

You should think about using a Java installer / wrapper which will create a native binary which contains your code / jar and the JRE (some solutions can even download a JRE for you) The positive side effect is that you (if needed) can create solutions for Linux, Windows and Mac.

If you want to stick to a simple Linux only solution you might want to try this: Bash script containing binary executable

Community
  • 1
  • 1
Marged
  • 10,577
  • 10
  • 57
  • 99
  • I was looking for an out-of-the-box solution provided by spring, which does not seem to exist. So this is the best answer, accepting it as the solution now. – hennr Sep 25 '15 at 17:38