Search code examples
mavenservletsjettyjakarta-migration

Jetty 11 doesn't detect Jakarta servlets, how can I debug it?


This is a followup to this question.

I have the same situation, and think I have followed the instructions in the answer by Joakim, and the EmbedMe code. I tried to run exec:java with the -X switch, but couldn't see anything related to scanning for servlets there. I also tried to set the LEVEL=DEBUG for org.eclipse.jetty.annotations.AnnotationConfiguration

but no luck. The servlets works fine with Java 8.

Everything compiles, the server starts with mvn exec:java and the welcome screen is shown, but all servlets return 404

Here is my main class:

public static void main(String[] args) throws Exception {
    // Create a server that listens on port 8080.
    int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
    String host = System.getenv("HOST");
    Server server;
    if (host != null)
        server = new Server(new InetSocketAddress("dev.ourwines.com", port));
    else
        server = new Server(port);

    WebAppContext context = new WebAppContext();
    context.setContextPath("/");
    context.setWelcomeFiles(new String[]{"index.html"});
    context.setParentLoaderPriority(true);

    URL webAppDir =
        Main.class.getClassLoader().getResource("META-INF/resources");
    System.out.println("webAppDir " + webAppDir);
    context.setResourceBase(webAppDir.toURI().toString());
    context.setParentLoaderPriority(true);

    server.setHandler(context);


    
    System.out.println("Configuration discovered? " + context.isConfigurationDiscovered());
    System.out.println("getBaseResource " + context.getBaseResource());
    String [] classes = context.getConfigurationClasses();
    for (int i = 0; i<classes.length; i++)
        System.out.println("getConfigurationClasses " + classes[i]);
    // server.setDumpAfterStart(true);
    server.start();
}

Solution

  • I think the root cause was the structure of the fat jar. We also switched to Tomcat and got this part working.