Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Jetty Server Classpath Issue

I'm trying to deploy a web application on an embedded Jetty Server. My application runs fine locally in a windows environment with the code below but when i deploy it as a JAR File on a Linux Server, it looks like my web.xml File is not picked up. Is there something i need to change in Descriptor or ResourceBase fields below before building a JAR?

static void startJetty() {
        try {
            Server server = new Server(9090); 
            WebAppContext context = new WebAppContext();
            context.setDescriptor("/WEB-INF/web.xml");                     
            context.setResourceBase("../DemoWithMultiChannels/src/");
            context.setContextPath("/");            
            context.setParentLoaderPriority(true);   
            server.setHandler(context);

            System.out.println("Starting Server!");             
            server.start(); 
like image 912
user676567 Avatar asked Feb 28 '13 15:02

user676567


1 Answers

I had the same problem and just found the solution:
It was working fine when I run "java -jar ..." from terminal, but when I spawned it off from another project, web.xml was not picked up.

Reason was web.xml path was wrong, it was relative to original project, what I end up doing is:

context.setDescriptor(Launch.class.getResource("/WEB-INF/web.xml").toString());

If you don't use resource you just read the regular file inside your src folder, not the one inside the .jar

like image 197
acheron55 Avatar answered Sep 23 '22 13:09

acheron55