splekhanov
splekhanov

Reputation: 116

Deploying WAR file to Jetty: server is running, but application didn't start

I got Spring Boot 2.2.7.RELEASE application. Package it as war file and trying to deploy it locally with Jetty:

public static void startJetty() throws Exception {
    Server server = new Server(8080);
    WebAppContext context = new WebAppContext();
    context.setContextPath("/");
    File warFile = new File("target/rest-service/my-rest-service.war");
    context.setWar(warFile.getAbsolutePath());
    server.setHandler(context);
    server.start();
    server.dumpStdErr();
    server.join();
}

After this Jetty is up and running at localhost:8080, got no errors in log but it seems like the application didn't start. When I try to reach it the response is 404 NOT FOUND. Although I do see my application directories at localhost:8080 like /swagger-ui/ etc.

Upvotes: 0

Views: 1284

Answers (1)

M. Deinum
M. Deinum

Reputation: 124461

Drop that code and let Spring Boot handle it.

Assuming you have an application class named MyRestApplication you need to have the following.

@SpringBootApplication
public class MyRestApplication {

  public static void main(String[] args) {
    SpringApplication.run(MyRestApplication.class, args);
  }
}

Assuming you have Jetty as a dependency as well as spring-boot-starter-web you can just run this class.

You should also use the spring Boot plugin to create the war or jar and then you can just launch it.

java -jar my-rest-service.war and it will launch everything you need.

Upvotes: 2

Related Questions