P
P
Pavel Ivanov2014-09-19 04:03:05
Java
Pavel Ivanov, 2014-09-19 04:03:05

What is the correct way to create a war to run the built-in Jetty server?

Using IntelliJ IDEA I'm trying to create a war file to run with Jetty without using servlets.

The code is like this:

package org.example;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerList;

public class HelloWorld {

    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] {new SimpleHandler()});

        server.setHandler(handlers);

        server.start();
        server.join();
    }
}


When run directly from the console - mvn clean compile exec:java, everything works fine.
But, if you create a war file from the IDE, then when it is deployed in the browser, the contents of this file are displayed - the WEB-INF and META-INF folders.

What could be the reason?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
anyd3v, 2014-09-19
@eastywest

You launch an application (namely a java application) and set a handler for it, which is visible and processed when requests are received. In the case of deploying to a container, your handler installation code will not be executed and, accordingly, you get the current behavior. You have 2 ways:
1. run your application as a java application (java -jar ...)
2. write your handler in the server config

P
Pavel Ivanov, 2014-09-25
@eastywest

As a result, I settled on a way to run java -jar
To do this, I create one jar file with all the libraries

N
Nikolai Pavlov, 2014-10-22
@gurinderu

What you wrote cannot be run in a container. In fact, you create a container with your hands, why do you need it at all?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question