Search code examples
spring-bootprocessbuilder

Start a spring boot application inside another java application?


I have two java applications:

  • a server starting with spring boot
  • a client using it (through REST api)

For the time, I start both applications in differents processes.

How could I start the server from the client to obtain a "standalone" application? The use of ProcessBuilder to call java.exe is a solution, but it has drawbacks: it will be OS dependant and cannot assure the server process will be shutdown / killed as the client leaves.


Solution

  • I found a solution in https://www.toptal.com/spring-boot/spring-boot-application-programmatic-launch . Igor Delac

    • opens the jar file containing the server to find the class ...loader.archive.JarFileArchive (and some other)
    • instanciates it and uses it to start the application on the jar itself.

    The jar file is not extracted nor modified. Only a few classes are read.