I have built an eclipse plug-in project which uses org.eclipse.core.runtime.applications to run the entry point method in a class called, public class Application implements IApplication. Yes, the project uses org.eclipse.equinox.app.IApplication to essentially build a headless application. I have created a launch configuration for this project which runs the application successfully. Do note that this project runs the eclipse platform (see code below).
So, while the eclipse platform is running, I also want a web server to run (for example Spring Boot). I have noticed, however, that Spring Boot and most other Java web server frameworks have to be initialised from a main function. How can I run both my plug-in project (which runs the eclipse platform) and incorporate a running web server from Spring Boot?
The code below shows what I have now. I want to know what I can add or even change to my project to incorporate a web server.
Here is the Application.java file:
// I have removed the package line of code (e.g com.example.test)
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
public class Application implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {
Path programDirectory;
try {
programDirectory = Paths.get(org.eclipse.core.runtime.Platform.getInstallLocation().getURL().toURI()).toAbsolutePath();
} catch (URISyntaxException e) {
System.err.println("Unable to determine the location of the software: " + org.eclipse.core.runtime.Platform.getInstallLocation().getURL().toString());
e.printStackTrace();
return IApplication.EXIT_OK;
}
// Run application (JUST RUNS AN EXTERNAL METHOD)
HandleSubmission.handleSubmissionMain(programDirectory);
Thread.sleep(100);
return IApplication.EXIT_OK;
}
@Override
public void stop() {
// Nothing to do
}
}
Here is the Activator.java file:
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
}
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
}
I tried to create a separate java file called SpringBootApp.java which holds the logic and server code for Spring Boot. I did of course import the Spring Boot dependencies into the plugin project. Then, I called the method: SpringBootApplication.run(SpringBootApp.class) in the start method of Application.java (the one which is the entry point to the plugin project). This showed errors such as "Failed to initialise embedded tomcat", or, "Child component failed".