IntelliData IntelliData - 1 year ago 103
Java Question

Webapplication in Embedded Jetty getting Error 404 Not found

I want to deploy a Java Netbeans Webapp with an embedded Jetty Server; the server itself works, but I always get the following error:

enter image description here

I searched through mounds of examples on the web, configured & reconfigured my web.xml; although my configuration seems fine, I can't get it to work.

I should point out, that when I run the app from whithin Netbeans using the built-in Glassfish server, it works fine, which tells me that web.xml is probably configured well.

Can anyone help with this?

My code follows.

P.S. I know that it's been asked on SO, but those examples did not work for me either.

Project structure:

enter image description here

WebContext setup:

import org.eclipse.jetty.webapp.WebAppContext;

public class AppContextBuilder {

private WebAppContext webAppContext;

public WebAppContext buildWebAppContext() {
webAppContext = new WebAppContext();
webAppContext.setDescriptor(webAppContext + "/WEB-INF/web.xml");

return webAppContext;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;

public class JettyServer {

private Server server;

public JettyServer() {

public JettyServer(Integer runningPort) {
server = new Server(runningPort);

public void setHandler(ContextHandlerCollection contexts) {

public void start() throws Exception {

public void stop() throws Exception {

public boolean isStarted() {
return server.isStarted();

public boolean isStopped() {
return server.isStopped();
} (main method):

import org.apache.log4j.Logger;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;

* @author Motty Waldner <>

public class Deploy {

private final static Logger log = Logger.getLogger(Deploy.class);

static JettyServer jettyServer = new JettyServer();

public static void main(String[] args) throws Exception {
// add hook to stop server upon service termination
// (service calls System.exit(0) upon termination,
// so it should work under normal circumstances)

ContextHandlerCollection contexts = new ContextHandlerCollection();
Handler[] handlers = new Handler[]{new AppContextBuilder().buildWebAppContext().getHandler()};

jettyServer = new JettyServer();

try {
} catch (Exception e) {
log.error("Error Starting Jetty Server", e);

private static void addShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
jettyServer.stop();"Shutdown Hook is running: Jetty Server instance being stopped.");
} catch (Exception e) {
log.error("error", e);
}"Application Terminating ...");


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<display-name>Test App</display-name>


<filter-name> struts2 </filter-name>





Thanks in advance for the help!

Answer Source

I just realised I ommited a very important line of code:


Of course it works now...

I just put 50 points to bed for a bounty... oh well :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download