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();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With