Add ServerConfig class to initialize and start the server

This commit is contained in:
Vincent Guillet
2025-05-23 11:23:35 +02:00
parent 0887925477
commit adbdf0d619

View File

@@ -0,0 +1,32 @@
package com.humanbooster.config;
import com.humanbooster.api.ApiApplication;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
public class ServerConfig {
public void startServer() throws Exception {
System.out.println("Starting server...");
ResourceConfig config = new ApiApplication();
ServletHolder servlet = new ServletHolder(new ServletContainer(config));
Server server = new Server(80);
ServletContextHandler context = new ServletContextHandler(server, "/");
context.setServer(server);
context.addServlet(servlet, "/*");
try {
server.start();
System.out.println("Server started on port 80");
server.join();
} catch (Exception e) {
System.out.println("Failed to start server: " + e.getMessage());
}
}
}