Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] (no subject)

Good morning!

(This is a repost of a Stack Overflow question I posted on Friday - I then realised this was a better place to ask..)

I'm trying to get Jetty 9.4.30 running as an OSGi Service (following this: https://examples.javacodegeeks.com/enterprise-java/jetty/jetty-osgi-example/ with updated versions) that can host WebApp Bundles. I can deploy and servlets work fine, but JSPs aren't working and I keep hitting an exception for TLD loading caused by:

Caused by: 
java.lang.NullPointerException
    at org.apache.jasper.JspCompilationContext.getTldResourcePath(JspCompilationContext.java:563)
    at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:430)
    at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:489)

The problem is almost exactly that described at http://bengreen.eu/fancyhtml/quickreference/jettyjsp9error.html, except that in this case the author is using Jetty as Embedded and is able to set org.eclipse.jetty.containerInitializers using code where the server is started.

In OSGi, I don't have a place where I'm starting it - it's all happening in the bundles. After a lot of tweaking (and untweaking) config files the closest I feel I've got is when I copied the configuration performed in code into the jetty-web.xml file (which would be deployed in each WAB and isn't ideal in itself) as follows:

<Configure id="webappctxt" class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="initList" class="java.util.ArrayList"></New>
    <Call name="setAttribute">
        <Arg>org.eclipse.jetty.containerInitializers</Arg>
        <Arg>
            <Call class="java.util.Arrays" name="asList">
                <Array type="org.eclipse.jetty.plus.annotation.ContainerInitializer">
                    <Item>
                        <New
                            class="org.eclipse.jetty.plus.annotation.ContainerInitializer">
                            <Arg>
                                <New class="org.eclipse.jetty.apache.jsp.JettyJasperInitializer"></New>
                            </Arg>
                            <Arg></Arg>
                        </New>
                    </Item>
                </Array>
            </Call>
        </Arg>
    </Call>
    <Call name="addBean">
        <Arg>
            <New class="org.eclipse.jetty.annotations.ServletContainerInitializersStarter">
                <Arg>
                    <Ref refid="webappctxt" />
                </Arg>
            </New>
        </Arg>
    </Call>
    <Get name="ServletContext">
        <Call name="setAttribute">
            <Arg>org.apache.tomcat.InstanceManager</Arg>
            <Arg>
                <New class="org.apache.tomcat.SimpleInstanceManager"></New>
            </Arg>
        </Call>
    </Get>
</Configure>

When running, I can see the org.eclipse.jetty.annotations.ServletContainerInitializersStarter, and it has the TLDs from the platform (so all my dependencies seem to be there!) but the XML version of the code fails because there are two constructors for org.eclipse.jetty.plus.annotation.ContainerInitializer:

ContainerInitializer(java.lang.ClassLoader loader, java.lang.String toString)   
ContainerInitializer(javax.servlet.ServletContainerInitializer target, java.lang.Class<?>[] classes)

...and the Jetty XML code picks the first one and throws a "java.lang.IllegalArgumentException: argument type mismatch".

Plugins currently "required" by my WAB are:

Require-Bundle: org.eclipse.jetty.jndi;bundle-version="9.4.30",
 org.mortbay.jasper.apache-jsp;bundle-version="8.5.54",
 org.eclipse.jetty.server;bundle-version="9.4.30",
 org.eclipse.jetty.deploy;bundle-version="9.4.30",
 org.eclipse.jetty.http;bundle-version="9.4.30",
 org.eclipse.jetty.io;bundle-version="9.4.30",
 org.eclipse.jetty.osgi.boot;bundle-version="9.4.30",
 org.eclipse.jetty.security;bundle-version="9.4.30",
 org.eclipse.jetty.servlet;bundle-version="9.4.30",
 org.eclipse.jetty.util;bundle-version="9.4.30",
 org.eclipse.jetty.webapp;bundle-version="9.4.30",
 org.eclipse.jetty.xml;bundle-version="9.4.30",
 org.eclipse.jetty.annotations;bundle-version="9.4.30",
 org.eclipse.jetty.apache-jsp;bundle-version="9.4.30"

...and only the WAB bundle is set to auto-start.

For completeness, the VM arguments to configure plugins are:

-Djetty.home.bundle=jetty-config-bundle -Djava.naming.factory.url.pkgs=org.eclipse.jetty.jndi -Djava.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory

And jetty-config-bundle does contain the jetty.xml, etc. files and they are being processed.

Can anyone tell me if they've got this working, and how? Is it configurable to just work without needing a jetty-web.xml in each WAB, or am I missing a dependency bundle on my plugin?

Thanks in advance,

Gordon Jahn


Back to the top