Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Having trouble using Embedded Jetty and WebApplicationInitializer with a WarFile deployment

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)

        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:
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

Jetty will see the @HandlesType(WebApplicationInitializer.class) on that ServletContainerInitializer and call the standard
ServletContainerInitializer.onStartup(Set<Class<?>> webAppInitializerClasses, ServletContext servletContext) 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 <joakim@xxxxxxxxxxx>
Expert advice, services and support from from the Jetty & CometD experts

On Tue, Sep 23, 2014 at 12:11 PM, David Kowis <dkowis+jettyUsers@xxxxxxxxx> wrote:
On 09/23/2014 12:58 PM, David Kowis wrote:
> I found this thread:

I found a couple more things:

So now I've got an additional commit:

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
> 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:
> 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
> jetty-users@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit

jetty-users mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top