OK this is kind of related to : Using jetty to install and run servlet tests programmatically
got great answers there, and have been able to load up servlets programmatically and its all made of awesome.
What I would like to do however is load up a web.xml in a test (all in the classpath) and have it run up a server (using the current classpath) - I have seen in docs how to point it to a directory to do that, but I want to work off the classpath (better for in place testing). Essentially validating my web.xml.
(its not relevant, but this app is in scala, but I have had no issue with that, everything works as advertised).
It sounds like what you want to do is load a proper web application programatically, as opposed to loading individual servlets (and I think you want to do it without having a full WAR file to work from).
Server server = new Server( port );
WebAppContext root = new WebAppContext();
root.setWar("/path/to/somewhere");
root.setContextPath("/");
server.addHandler( root );
server.start();
The trick is that the /path/to/somewhere
should contain a WEB-INF
directory and your web.xml
file should live inside there. Nothing else needs to live within that directory structure, as everything else can be automatically loaded from your classpath (though if you wanted to, you could make that a path to an actual WAR file or complete exploded WAR tree).
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