Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] embedded jetty 9 JSP: NullPointerException in org.apache.jasper.compiler.Validator

Lothar & Joakim: thanks much for your responces.


Joakim:


>Per the JSP spec the Java support level is Java 6 (and it still is, even today).
>Notice that Jetty 6 doesn't use Java itself to compile JSPs?
>Jetty 6 is using the Eclipse JDT compiler.
>Breaking spec to support Java 8 is handled by configuring to use Java and JavaC itself.

Does this mean that I can continue using jetty 6, so long as I configure it to not use JDT but instead to use my JDK 8's javac?

I would love for that to be true, as it should be the quickest way for me to resolve the conflict between jetty 6 and JDK 8.

Assuming that, how do you so configure jetty 6 to use javac?  A web search came up empty.  The codehaus website is defunct, and does not seem to be archived anywhere.


I tried some guesses.  The most important being:

1) as per your github page, I added a call to
    System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");
before I create a Server instance, but that fails--I still see
    2015-08-26T18:21:12.783-0400 WARN [842741472@qtp-1002021887-0] - Compilation error
    org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException: null
        at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:298) ~[core-3.1.1.jar:na]
        at org.apache.jasper.compiler.JDTJavaCompiler$1.findType(JDTJavaCompiler.java:351) [jsp-2.1.jar:6.1.11]
        ...
I guess that property must be for newer jetty (e.g. jetty 7+)?

2) I tried removing the core-3.1.1.jar file from my lib directory, as that jar contains the JDT classes, but that caused a different error:
    2015-08-26T18:42:46.485-0400 ERROR [1712943792@qtp-1202683709-0] - /errors.jsp
    java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildListener
        at org.apache.jasper.compiler.Compiler.initJavaCompiler(Compiler.java:716) ~[jsp-2.1.jar:6.1.11]
        at org.apache.jasper.compiler.Compiler.<init>(Compiler.java:116) ~[jsp-2.1.jar:6.1.11]
        ...


>You really should use some sort of build system.

The decision is not 100% mine to make, and involves as many political factors as technical.

I can use whatever I want when playing around on my own workstation (e.g. to determine dependent jars), but forcing other users our or prd servers to use, say maven, may be impossible.


>>Doing a more focused web search found:
>>    --this link, which reports what looks like the same problem (but has no solution):
>>        http://jspl598.blogspot.com/2015/03/while-accessing-jsps-in-jetty_13.html

>This looks like your blog.

No it is not!

>Its identical to what you are describing.
>Why they didn't use this forum, or stackoverflow, i cannot comprehend.

Agreed.


I think that our use of jetty 6 is very similar to what is described here:
    https://stackoverflow.com/questions/15282678/how-does-jetty-compile-jsps

Perhaps it will help if I post the code we use to embed jetty.

Our application has a Main class that is its entry point. The sole jetty code is entirely in these 3 methods of Main:

    private static void startWebServer() throws Exception {
        Server server = new Server();
        server.setConnectors(makeJettyConnectors());
        server.setHandler(makeJettyHandler());
        server.start();
    }
   
    private static Connector[] makeJettyConnectors() {
        Connector connector = new SelectChannelConnector();
        connector.setPort(Integer.parseInt(PropMgr.getProperty("http.port")));
        return new Connector[] {connector};
    }
   
    private static Handler makeJettyHandler() {
        WebAppContext context = new WebAppContext();
        context.setContextPath("/");
        context.setResourceBase(urlOfWebDir());
        context.setDefaultsDescriptor(urlOfFile("/webdefault.xml"));    // the / prefix means to start the search at the class path root
        return context;
    }

Main's static initializer calls startWebServer.

In addition to that code in Main, there is also:
    1) a web directory, containing the .jsp files and a bunch of other stuff
    2) a .../config/webdefault.xml file
    3) these jars, which I think are all jars we use for jetty/JSP:
        core-3.1.1.jar
        direct-client.jar
        jetty-6.1.12.jar
        jetty-util-6.1.12.jar
        jsp-2.1.jar
        jsp-api-2.1.jar
        servlet-api-2.5-6.1.11.jar

I mentioned above that I tried using
    System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");
to disable JDT; I put that call as the first line in startWebServer.

I also tried adding this line
    context.setClassLoader(getUrlClassLoader());
as the 2nd line of makeJettyHandler, since your github page also mentions it; that too made no difference (probably for the same reason).

Back to the top