[
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
|
On 09/23/2014 04:05 PM, Joakim Erdfelt wrote:
> So I took your project, cloned it, made no changes, built it, ran it,
> and I do not get your error.
>
> http://pastebin.com/0Lnca9Bn
Yep, running as a standalone war file in jetty always worked, that's not
broke at all.
Try checking out the warDeploy branch and doing `gradle run`
That will run the embedded jetty, rather than deploying a war file to
the jetty plugin. (Should also eliminate the logback conflicting
dependency, since it won't pull in the gradle classpath)
--
David
>
>
>
> --
> Joakim Erdfelt <joakim@xxxxxxxxxxx <mailto:joakim@xxxxxxxxxxx>>
> webtide.com <http://www.webtide.com/> - intalio.com/jetty
> <http://intalio.com/jetty>
> Expert advice, services and support from from the Jetty & CometD experts
> eclipse.org/jetty <http://eclipse.org/jetty/> - cometd.org
> <http://cometd.org/>
>
> On Tue, Sep 23, 2014 at 1:28 PM, David Kowis
> <dkowis+jettyUsers@xxxxxxxxx <mailto:dkowis+jettyUsers@xxxxxxxxx>> wrote:
>
> On 09/23/2014 02:39 PM, Joakim Erdfelt wrote:
> > A few things.
> > You seem to be grasping at straws in your code.
>
> Sadly, this is somewhat true, I have a few questions regarding the
> suggestions.
>
> >
> > 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()
> > });
>
> Why do I need to declare all of these? As I understand it, I should only
> need the ones that affect the container config that I want (Like if I
> don't have any web-fragment.xmls I could skip the
> FragmentConfiguration.) (I'll note that it takes significantly longer to
> start up when they're all configured, vs when I only include the ones I
> need)
>
> So in that example, it requires that you setParentLoaderPriority(true),
> which changes the way classloading happens. If I set that to true, my
> war deployment works, but it will not ever work with it set to false.
> Why is this the case, but it works fine if I were to run the war file
> with a standalone jetty (say with jetty-launcher)?
>
> >
> > Next, you'll require jetty-annotations.jar (and transitive dependencies)
> > in your environment too.
>
> Yep, no problem there. It also appears that I need to have spring-web in
> the environment that I start jetty in, else it doesn't do the spring
> WebApplicationInitializer detection at all.
>
> //Without spring-web
> 15:21:05.217 INFO o.e.j.s.Server - jetty-9.2.3.v20140905
> 15:21:06.509 INFO o.e.j.w.StandardDescriptorProcessor - NO JSP Support
> for /, did not find org.apache.jasper.servlet.JspServlet
> 15:21:06.528 INFO o.e.j.s.h.ContextHandler - Started
> o.e.j.w.WebAppContext@13dbe345{/,file:/tmp/jetty-0.0.0.0-8080-war-1.NOPE.war-_-any-7447262048590329370.dir/webapp/,AVAILABLE}{/home/dkowis/gitwork/repose/Valve2/valve/build/war-1.NOPE.war}
>
>
> //with spring-web
> 15:21:34.659 INFO o.e.j.w.StandardDescriptorProcessor - NO JSP Support
> for /, did not find org.apache.jasper.servlet.JspServlet
> 15:21:34.663 INFO / - No Spring WebApplicationInitializer types
> detected on classpath
> 15:21:34.679 INFO o.e.j.s.h.ContextHandler - Started
> o.e.j.w.WebAppContext@7709d976{/,file:/tmp/jetty-0.0.0.0-8080-war-1.NOPE.war-_-any-2624512083090645583.dir/webapp/,AVAILABLE}{/home/dkowis/gitwork/repose/Valve2/valve/build/war-1.NOPE.war}
>
>
> >
> > 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.
>
> I've got all this, but it's not happening.
>
> My war file contents:
> https://gist.github.com/dkowis/ffba7f0dc84e1d7d1bef
>
> I have the things you describe, but it doesn't behave the way you
> describe. I'll push up some commits for this project demonstrating this
> on a branch: https://github.com/dkowis/valve2/tree/warDeploy
>
> Unless I've missed something, the environment you describe I've
> duplicated, but it's not working. (Maybe I did miss something)
>
> >
> > Good luck
> >
> > --
> > Joakim Erdfelt <joakim@xxxxxxxxxxx <mailto:joakim@xxxxxxxxxxx>
> <mailto:joakim@xxxxxxxxxxx <mailto:joakim@xxxxxxxxxxx>>>
> > webtide.com <http://webtide.com> <http://www.webtide.com/> -
> intalio.com/jetty <http://intalio.com/jetty>
> > <http://intalio.com/jetty>
> > Expert advice, services and support from from the Jetty & CometD experts
> > eclipse.org/jetty <http://eclipse.org/jetty>
> <http://eclipse.org/jetty/> - cometd.org <http://cometd.org>
> > <http://cometd.org/>
> >
> > On Tue, Sep 23, 2014 at 12:11 PM, David Kowis
> > <dkowis+jettyUsers@xxxxxxxxx
> <mailto:dkowis%2BjettyUsers@xxxxxxxxx>
> <mailto:dkowis+jettyUsers@xxxxxxxxx
> <mailto:dkowis%2BjettyUsers@xxxxxxxxx>>> 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
> > > jetty-users@xxxxxxxxxxx <mailto:jetty-users@xxxxxxxxxxx>
> <mailto:jetty-users@xxxxxxxxxxx <mailto:jetty-users@xxxxxxxxxxx>>
> > > 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
> > jetty-users@xxxxxxxxxxx <mailto:jetty-users@xxxxxxxxxxx>
> <mailto:jetty-users@xxxxxxxxxxx <mailto:jetty-users@xxxxxxxxxxx>>
> > 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
> > jetty-users@xxxxxxxxxxx <mailto:jetty-users@xxxxxxxxxxx>
> > 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
> jetty-users@xxxxxxxxxxx <mailto:jetty-users@xxxxxxxxxxx>
> 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
> jetty-users@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>