A few things.
You seem to be grasping at straws in your code.
First, you'll need a proper set of WebAppContext configurations (declared
all of them, in the correct order)
Example:
https://github.com/jetty-project/embedded-servlet-3.1/blob/master/src/test/java/org/eclipse/jetty/demo/EmbedMe.java#L28-L38
context.setConfigurations(new Configuration[]
{
new AnnotationConfiguration(),
new WebInfConfiguration(),
new WebXmlConfiguration(),
new MetaInfConfiguration(),
new FragmentConfiguration(),
new EnvConfiguration(),
new PlusConfiguration(),
new JettyWebXmlConfiguration()
});
Next, you'll require jetty-annotations.jar (and transitive dependencies) in
your environment too.
After that, you'll need to make sure that the following are in your
WEB-INF/lib directories
The spring jar(s) that contains the classes:
- org.springframework.web.SpringServletContainerInitializer
<https://github.com/spring-projects/spring-framework/blob/v4.1.0.RELEASE/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java>
(this is the class that Jetty finds and calls)
- org.springframework.web.WebApplicationInitializer
<https://github.com/spring-projects/spring-framework/blob/v4.1.0.RELEASE/spring-web/src/main/java/org/springframework/web/WebApplicationInitializer.java>
(this is the type of class that the SpringServletContainerInitializer has
stated that it handles
<https://github.com/spring-projects/spring-framework/blob/v4.1.0.RELEASE/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java#L110>
)
Make sure these are only in your webapp's WEB-INF/lib directory.
Then, all of your classes that implement WebApplicationInitializer should
be in WEB-INF/classes/ or WEB-INF/lib/
That should be it.
What happens is Jetty scans all of your container jars, then WEB-INF/lib
jars, then WEB-INF/classes files.
In the process, it sees that WEB-INF/lib/spring-something.jar has a
resource called META-INF/services/javax.servlet.ServletContainerInitializer
which references the
org.springframework.web.SpringServletContainerInitializer
<https://github.com/spring-projects/spring-framework/blob/v4.1.0.RELEASE/spring-web/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer>
Jetty will see the @HandlesType(WebApplicationInitializer.class) on that
ServletContainerInitializer and call the standard
ServletContainerInitializer.onStartup(Set<Class<?>>
webAppInitializerClasses, ServletContext servletContext)
<https://github.com/spring-projects/spring-framework/blob/v4.1.0.RELEASE/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java#L145>
with all of the classes that implement WebApplicationInitializer that it
has found.
At this point, Jetty is out of the equation and Spring is doing the rest of
the initialization for itself.
Good luck
--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/> - intalio.com/jetty
Expert advice, services and support from from the Jetty & CometD experts
eclipse.org/jetty - cometd.org
On Tue, Sep 23, 2014 at 12:11 PM, David Kowis <[email protected]>
wrote:
> On 09/23/2014 12:58 PM, David Kowis wrote:
> > I found this thread:
> > http://dev.eclipse.org/mhonarc/lists/jetty-users/msg04587.html
>
> I found a couple more things:
> http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html
>
> So now I've got an additional commit:
> a44cb9a9a5437fd1eee60d6071d5fc4ef8f8ce79
>
> This works, but it only works if I set parentLoaderPriority(true), from
> the documentation I'm not exactly clear as to why this works.
>
> The classes I want to load are all in the War file themselves, they
> shouldn't be necessary in the classpath that I'm configuring the server
> in. There must be something else wrong...
>
> I don't want to include the classes in the launcher project's classpath,
> when they should all be in the war file.
>
> I have this working with the servlet launcher mechanism, because I do
> want to actaully share some things in a spring context at one level
> higher than the war files, so perhaps it's best if I don't try to deploy
> lots of war files, and just have the jetties be in my one classpath.
>
> --
> David Kowis
>
> >
> > It gets me part of the way there, but I'm not deploying using a
> > directory, I'm deploying using an existing war file.
> > Jetty Version: 9.2.3.v20140905
> >
> > I tried setting:
> > (note this is Scala, but it doesn't really matter in this context)
> > val webapp = new WebAppContext()
> > webapp.setContextPath("/")
> > webapp.setWar(config.getString("warLocation"))
> >
> webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
> > ".*/WEB-INF/classes/.*")
> >
> > I'm not sure how to get it to pick up my WebAppInitializer class. The
> > jetty logs indicate that it has tried, but not found anything:
> > 12:54:15.653 INFO / - No Spring WebApplicationInitializer types
> > detected on classpath
> >
> >
> > I'll note that the warfile deploys beautifully in Jetty 9 using
> > https://github.com/Khoulaiz/gradle-jetty-eclipse-plugin
> >
> > Its only when I'm trying to do it myself, using this simple embedded
> > mechanism that it doesn't work. I'm probably missing something obvious,
> > but I can't quite figure it out.
> >
> > The project is here: https://github.com/dkowis/valve2
> >
> > You can get here with `gradle run` (I'm using gradle 2.x) at the root,
> > at commit 9db7cc77f5
> >
> > Thanks in advance!
> > David Kowis
> >
> > PS: sorry for double send if this happened, I sent the other using the
> > wrong email address.
> > _______________________________________________
> > jetty-users mailing list
> > [email protected]
> > To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> > https://dev.eclipse.org/mailman/listinfo/jetty-users
> >
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users