I want to use jsvc to start my spring boot application because it's on the target system already and the alternative is to spend time debugging shell scripts for edge cases. I've implemented the Daemon interface so that SpringApplication.run()
is called in Daemon.start()
but the nested jars cannot be found because I've bypassed the JarLoader
.
Is there a way to programatically set up the correct class loaders etc.?
@Configuration
@EnableAutoConfiguration
@ComponentScan
@EnableConfigurationProperties
public class Application implements Daemon {
private ConfigurableApplicationContext ctx;
private String[] args;
@Override
public void init(DaemonContext context) throws Exception {
args = context.getArguments();
}
@Override
public void start() throws Exception {
ctx = SpringApplication.run(Application.class, args);
}
@Override
public void stop() throws Exception {
ctx.stop();
}
@Override
public void destroy() {
ctx.close();
}
// Main - mostly for development.
public static void main(String[] args) throws Exception {
System.err.println("WARNING - running as current user");
DaemonLoader.Context ctx = new DaemonLoader.Context();
Application app = new Application();
ctx.setArguments(args);
app.init(ctx);
app.start();
}
}
This errors with
java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
I've solved this problem.
I had to produce shaded jar instead of fat jar. Then instead of using JarLoader, i've changed the main class directly to my main class. In case of original poster to class "Application".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With