Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 342972

Summary: Servlet 3.0 features should be easier to use when embedding / non-standard deployments
Product: [RT] Jetty Reporter: Eirik Bjørsnøs <eirbjo>
Component: serverAssignee: Jan Bartel <janb>
Status: CLOSED WORKSFORME QA Contact:
Severity: enhancement    
Priority: P3 CC: digulla, gregw, jetty-inbox
Version: unspecified   
Target Milestone: 7.2.x   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Eirik Bjørsnøs CLA 2011-04-15 09:50:04 EDT
Build Identifier: 


Servlet 3.0's META-INF/resources and web-fragment.xml don't work if the containing jars are not in WEB-INF/lib but on the parent class loader. Two cases where this happens is when embedding Jetty in a main method inside the IDE or when creating Maven plugins running from unpacked sources (like jetty:run does).

jetty:run does a bit of magic with custom configurations to make this work, but ideally Jetty should be easy to use in embedded/non-standard deployments.

We should investigate options that will either make this work out of the box or that will enable it with minimal configuration switches and without having to subclass Jetty. 

Reproducible: Always
Comment 1 Eirik Bjørsnøs CLA 2011-04-15 09:54:46 EDT
See also thread on jetty-dev:

http://dev.eclipse.org/mhonarc/lists/jetty-dev/msg00902.html
Comment 2 Jan Bartel CLA 2012-01-29 23:46:11 EST
The difficulty here is that in an embedded scenario such as Eclipse, the classloaders used are not URLClassloaders, therefore we cannot retrieve the list of jars as urls and apply the pattern match for the container jars.
Comment 3 Eirik Bjørsnøs CLA 2012-02-08 04:32:43 EST
I'm not looking for the one and only solution for all cases here :-)

What I would like is just to make the typical Jetty-in-main-method case easier. 

Something like an EmbeddedConfiguration class which locates META-INF/resources on the classpath would be fine. It could probably inherit much of its code from jetty:run


Think:

WebAppContext ctx = new WebAppContext("src/main/webapp/", "/");

// Enable Servlet3.0 for embedded use where jar are not in WEB-INF/lib
ctx.addConfigurationClass(EmbeddedServlet3Configuration.class);

server.setHandler(ctx);

server.start();


Without this, Jetty is pretty much broken with the quick-start-from-main-method case..

Then we could probably add another configuration (OsgiConfiguration) which inspects bundles for META-INF/resources.
Comment 4 Greg Wilkins CLA 2012-08-31 02:38:51 EDT
There are two aspects of this I think:

1) making sure that all the configuration classes are set that are needed
2) parameterizing the configuration - for example by telling it of jars to scan or fragments that exist outside of the normal webapplication structure.

I'm not sure there is much we want to do here in jetty-8, but we can potentially be rather radical with jetty-9.

For example, I wonder if the context really needs to array of configuration classes anymore - it really should just of a List of Configuration instances and we can make a simple factory (used by the deployer or set by default) to instantiate the configuration list.

Once we simplify and update the context to just have a List of configuration, then it is much simpler to add instances to that.  Some of these instances could indeed be utility instances designed to inject parameters such as searching outside of the webapp structure.


Would something in the Jetty-9 time frame be OK?  (beta release next month, stable release end of year).
Comment 5 Jan Bartel CLA 2015-04-02 01:21:41 EDT
Hi Eirik,

I think the later versions of jetty-9 support this via the WebInfConfiguration.CONTAINER_JAR_PATTERN.

We will scan any jar whose name matches the pattern for META-INF/resources, META-INF/fragment.xml, META-INF/*.tlds.  I know there are users who are using jetty in an embedded fashion via a runnable jar, so it seems to me we support this use-case.  

I'm going to close this issue, but feel free to reopen and attach a test harness to reproduce the problem and I'll take another look.

cheers
Jan
Comment 6 Aaron Digulla CLA 2017-06-09 04:35:01 EDT
WebInfConfiguration.CONTAINER_JAR_PATTERN doesn't work for projects (i.e. class folders) on the classpath.

My use case: Start my app in the IDE as normal Java process. That means I have half of the code in projects open in the workspace which end up on the classpath.

There are some places in Jetty which now fail to work, for example loading web-fragment.xml since there is a check which rejects the JAR when it's not in the WEB-INF/lib/ folder.

I've found a solution for projects that contain web-fragment.xml.
See this gist: 
https://gist.github.com/digulla/fb69b5df3b120f6e47b06130842d62cb
Comment 7 Jan Bartel CLA 2017-06-09 06:28:16 EDT
Hi Aaron,

Jetty has moved to using git issues instead, so can you raise one over at https://github.com/eclipse/jetty.project/issues

thanks