web applications - How to start webapp with embedded jetty from a different project -
here quick question: possible start web-app embedded jetty different project? trying run (with junit) following code:
server server = new server(80); webappcontext context = new webappcontext(); file webxml = new file("../project1/src/main/webapp/web-inf/web.xml"); context.setdescriptor(webxml.getabsolutepath()); context.setresourcebase("../project1/src/main/webapp"); context.setcontextpath("/"); context.setparentloaderpriority(false); server.sethandler(context); server.start();
if project, let's project2, jetty throws lot of exceptions: javax.servlet.unavailableexception: com.sun.xml.ws.transport.http.servlet.wsspringservlet java.lang.classnotfoundexception: com.sun.xml.ws.transport.http.servlet.wsspringservlet
i've tried adding project1 project's 2 classpath, doesn't situation. if try run same come within same project1 (with paths adjusted, of course) - works fine.
thank help.
this due relative path strings.
here's alternative approach using junit assert too...
server server = new server(80); webappcontext context = new webappcontext(); file otherproject = new file("../project1"); assert.asserttrue("project1 should exist", otherproject.exists()); // make path reference canonical (eliminate relative path reference) otherproject = otherproject.getcanonicalfile(); file webappdir = new file(otherproject, "src/main/webapp"); assert.asserttrue("webapp dir should exist", webappdir.exists()); file webxml = new file(webappdir, "web-inf/web.xml"); assert.asserttrue("web.xml should exist", webxml.exists()); context.setdescriptor(webxml.getabsolutepath()); context.setresourcebase(webappdir.getabsolutepath()); context.setcontextpath("/"); context.setparentloaderpriority(false); server.sethandler(context); server.start();
or due fact ../project1/src/main/webapp/web-inf/lib
not have dependencies need. important webappcontext use provided web-inf/lib
contents first, server classpath.
Comments
Post a Comment