embedded jetty 9 JSP: NullPointerException in org.apache.jasper.compiler.Validator

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

embedded jetty 9 JSP: NullPointerException in org.apache.jasper.compiler.Validator

Barbara Tuchman


~~~~~~~~~~ Background ~~~~~~~~~~


An application at work uses embedded jetty 6 to support a single web page that we use to control a trading application.  This was written long before I joined, but I am stuck with maintaining it.  The web page uses 4 .jsp files to perform various actions.  (The web page is actually a flash page: when you click on certain buttons, it calls the associated .jsp to carry out the action.)  Each .jsp file is actually very simple; all are <= 1 KB in size.

I want to update the JDK on our prd server from 7 to the latest 8 release.

Testing in UAT reveals that everything works except for this web page.  In particular, with jetty 6 and JDK 8, I see this error in the logs:
    2015-08-21T17:19:26.183-0400 WARN [qtp0-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]
        ...

Clearly, the ancient jdt compiler in jetty 6 cannot handle JDK 8 class files.  So, it is time to upgrade to a modern jetty version.

Unfortunately, when I try jetty 9, I get a NullPointerException in org.apache.jasper.compiler.Validator.  I cannot figure out why.  The rest of this email provides details.


~~~~~~~~~~ Step 1 ~~~~~~~~~~


The first issue that I was faced with in upgrading to a modern jetty is determining what jar files I need.  This is actually a nightmare, because:
    1) jetty 9 seems to have ~50 jars of its own, plus dependencies on ~50 more (see Step 3 below for proof)
    2) our project does not use maven or ant (just IntelliJ, as our project is fairly simple in regards to build requirements), and jetty seems to really want maven

I came across this web page
    https://www.eclipse.org/jetty/documentation/current/advanced-embedding.html
which mentions using a "jetty-all.jar" file to work around this problem.  So, I downloaded the latest stable one
    jetty-all-9.3.2.v20150730-uber.jar

I had to change some of my embedded code that launches the jetty server (e.g. to cope with new package names, slightly different API), but this was fairly straight forward.

Unfortunately, running my code failed: I see console logs like this:
    2015-08-21T16:50:48.165-0400 INFO [qtp889486595-18] {/} - No JSP support.  Check that JSP jars are in lib/jsp and that the JSP option has been specified to start.jar
(That log level probably ought to be ERROR, not INFO?)


~~~~~~~~~~ Step 2 ~~~~~~~~~~


A web search found a similar issue described here:
    https://stackoverflow.com/questions/26217143/embedded-jetty-server-no-jsp-support-for-did-not-find-org-apache-jasper-ser
Looks like the "all uber" jar file does not contain everything after all, contrary to its name.  In the link above,  Joakim Erdfelt eventually comments that
    "jetty-all.jar only exists as a teaching aid (referenced in the documentation), its not meant for production use"

Given that tip, since I had already downloaded a copy of the full 9.3.2.v20150730 distribution, I tried copying these additional 4 jars
    org.eclipse.jetty.apache-jsp-9.3.2.v20150730.jar
    org.eclipse.jetty.orbit.org.eclipse.jdt.core-3.8.2.v20130121.jar
    org.mortbay.jasper.apache-el-8.0.23.M1.jar
    org.mortbay.jasper.apache-jsp-8.0.23.M1.jar
from its lib/apache-jsp directory into my project's lib directory (where all its jar files live).

Running my code with these 4 additional jars now fails further on: I see this log:
    2015-08-21T16:54:30.933-0400 WARN [qtp1238959340-38] -
    org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        ...
    Caused by: java.lang.NullPointerException: null
        at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1853) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        ...


~~~~~~~~~~ Step 3 ~~~~~~~~~~


I got tired of guessing what jars my app needs, and decided on a simple brute force way to pull down everything:
    1) I deleted the 5 jetty jars described above from my app's lib directory
    2) I completely emptied my C:\Users\Sam\.m2\repository directory
    3) I downloaded the Embedded Jetty w/ JSP Support project
        https://github.com/jetty-project/embedded-jetty-jsp
    4) I built it (mvn clean package), started the server (mvn exec:exec), and verified that it worked in my browser (http://localhost:8080/)
    5) I copied every *.jar file from my C:\Users\Sam\.m2\repository directory (there are 100 of them!) into my app's lib directory

Running my code with these 100 jetty jars fails with a similar stack trace:
    2015-08-21T16:03:52.001-0400 WARN [qtp934275857-19] -
    org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:579) ~[apache-jsp-8.0.9.M3.jar:2.3]
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) ~[apache-jsp-8.0.9.M3.jar:2.3]
        ...
    Caused by: java.lang.NullPointerException: null
        at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515) ~[apache-jsp-8.0.9.M3.jar:2.3]
        at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1846) ~[apache-jsp-8.0.9.M3.jar:2.3]
        ...

This is probably essentially the same as Step 2 above: recall that Step 2 used jetty 9.3.2.v20150730, whereas the Embedded Jetty w/ JSP Support project still uses jetty-9.2.6.  So, that likely explains the different line numbers in the stack traces.


~~~~~~~~~~ Future work ~~~~~~~~~~


My conclusion after Step 3 is that I cannot be missing something on my classpath at this point.

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 link, which reports what looks like the same problem, claims to have a solution, but hides it behind subscription access:
        https://access.redhat.com/solutions/315013  
    --this link, which reports what looks like the same problem, and whose solution was to correct a typo in a .tld file:
        http://www.coderanch.com/t/614308/JSP/java/EL-function

The solution in that final link above suggests that there is some bug in my code.

I do not have any .tld files, so the precise solution there is not relevant for me.

I quickly inspected my .jsp files, and see nothing obviously wrong.  Furthermore, I note that the .jsp files all worked under jetty 6.

SO, DOES ANYONE HAVE ANY SUGGESTIONS FOR WHERE I CAN LOOK TO DEBUG THIS?

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: embedded jetty 9 JSP: NullPointerException in org.apache.jasper.compiler.Validator

Lothar Kimmeringer
Hi,

Am 24.08.2015 um 06:05 schrieb Barbara Tuchman:

> Given that tip, since I had already downloaded a copy of the full
> 9.3.2.v20150730 distribution, I tried copying these additional 4 jars
>     org.eclipse.jetty.apache-jsp-9.3.2.v20150730.jar
>     org.eclipse.jetty.orbit.org.eclipse.jdt.core-3.8.2.v20130121.jar
>     org.mortbay.jasper.apache-el-8.0.23.M1.jar
>     org.mortbay.jasper.apache-jsp-8.0.23.M1.jar
> from its lib/apache-jsp directory into my project's lib directory (where all its jar files live).

That's not enough. Here is my list of libraries for comparison:
 Verzeichnis von D:\ISDW3_devel\lib\jetty

07.05.2015  14:53    <DIR>          .
07.05.2015  14:53    <DIR>          ..
17.03.2015  15:52           241.639 asm-all.jar
26.03.2015  12:30           224.014 javax.el-3.0.0.jar
26.03.2015  12:30           547.677 javax.servlet.jsp-2.3.2.jar
26.03.2015  12:30            53.239 javax.servlet.jsp-api-2.3.1.jar
26.03.2015  12:30           405.951 javax.servlet.jsp.jstl-1.2.2.jar
26.03.2015  12:30         2.792.089 jetty-all-9.2.9.v20150224.jar
26.03.2015  12:30             5.321 jetty-jsp-9.2.9.v20150224.jar
26.03.2015  12:30            13.569 jetty-jsp-jdt-2.3.3.jar
07.05.2015  14:52           188.164 jetty-schemas-3.1.M0.jar
26.03.2015  12:30         1.764.622 org.eclipse.jdt.core-3.8.2.v20130121.jar
26.03.2015  12:30            51.761 org.eclipse.jetty.orbit.javax.servlet.jsp.jstl-1.2.0.v201105211821.jar
26.03.2015  12:30            95.806 servlet-api-3.1.jar


Cheers, Lothar
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: embedded jetty 9 JSP: NullPointerException in org.apache.jasper.compiler.Validator

Joakim Erdfelt-8
In reply to this post by Barbara Tuchman
Inline comments...

On Sun, Aug 23, 2015 at 9:05 PM, Barbara Tuchman <[hidden email]> wrote:


~~~~~~~~~~ Background ~~~~~~~~~~


An application at work uses embedded jetty 6 to support a single web page that we use to control a trading application.  This was written long before I joined, but I am stuck with maintaining it.  The web page uses 4 .jsp files to perform various actions.  (The web page is actually a flash page: when you click on certain buttons, it calls the associated .jsp to carry out the action.)  Each .jsp file is actually very simple; all are <= 1 KB in size.

I want to update the JDK on our prd server from 7 to the latest 8 release.

Testing in UAT reveals that everything works except for this web page.  In particular, with jetty 6 and JDK 8, I see this error in the logs:
    2015-08-21T17:19:26.183-0400 WARN [qtp0-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]
        ...

Clearly, the ancient jdt compiler in jetty 6 cannot handle JDK 8 class files.  So, it is time to upgrade to a modern jetty version.

Unfortunately, when I try jetty 9, I get a NullPointerException in org.apache.jasper.compiler.Validator.  I cannot figure out why.  The rest of this email provides details.


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.

 

~~~~~~~~~~ Step 1 ~~~~~~~~~~


The first issue that I was faced with in upgrading to a modern jetty is determining what jar files I need.  This is actually a nightmare, because:
    1) jetty 9 seems to have ~50 jars of its own, plus dependencies on ~50 more (see Step 3 below for proof)
    2) our project does not use maven or ant (just IntelliJ, as our project is fairly simple in regards to build requirements), and jetty seems to really want maven


Jetty is a 100% modular web container.
Nothing is mandatory. (Not even the Server!)
There is no concept of "all", "minimum", or "everything". (these mean different things to different people).

You really should use some sort of build system.
You have many to choose from.
Would recommend: Apache Maven, Grails, or Apache Ant+Ivy.
Alternative build tooling: Apache Buildr, Groovy Grape, Scala SBT, or Leiningen

IntelliJ supports Apache Maven and Grails *very well*.
Once you decide what you need, you reference just that, and let the build tooling pull in what's relevant. (eg: you want jsp, so you use "org.eclipse.jetty:apache-jsp:{jetty-version}", and you'll wind up with the jars that you need, resolved for conflicts and build/compile vs test scopes)

 
I came across this web page
    https://www.eclipse.org/jetty/documentation/current/advanced-embedding.html
which mentions using a "jetty-all.jar" file to work around this problem.  So, I downloaded the latest stable one
    jetty-all-9.3.2.v20150730-uber.jar

I had to change some of my embedded code that launches the jetty server (e.g. to cope with new package names, slightly different API), but this was fairly straight forward.

Unfortunately, running my code failed: I see console logs like this:
    2015-08-21T16:50:48.165-0400 INFO [qtp889486595-18] {/} - No JSP support.  Check that JSP jars are in lib/jsp and that the JSP option has been specified to start.jar
(That log level probably ought to be ERROR, not INFO?)

You should not use jetty-all.jar.
Something we use to help people understand jetty in our documentation. (and limited in scope to support only this task)
It's not meant to be used from any real world project.
 


~~~~~~~~~~ Step 2 ~~~~~~~~~~


A web search found a similar issue described here:
    https://stackoverflow.com/questions/26217143/embedded-jetty-server-no-jsp-support-for-did-not-find-org-apache-jasper-ser
Looks like the "all uber" jar file does not contain everything after all, contrary to its name.  In the link above,  Joakim Erdfelt eventually comments that
    "jetty-all.jar only exists as a teaching aid (referenced in the documentation), its not meant for production use"

Given that tip, since I had already downloaded a copy of the full 9.3.2.v20150730 distribution, I tried copying these additional 4 jars
    org.eclipse.jetty.apache-jsp-9.3.2.v20150730.jar
    org.eclipse.jetty.orbit.org.eclipse.jdt.core-3.8.2.v20130121.jar
    org.mortbay.jasper.apache-el-8.0.23.M1.jar
    org.mortbay.jasper.apache-jsp-8.0.23.M1.jar
from its lib/apache-jsp directory into my project's lib directory (where all its jar files live).

Running my code with these 4 additional jars now fails further on: I see this log:
    2015-08-21T16:54:30.933-0400 WARN [qtp1238959340-38] -
    org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        ...
    Caused by: java.lang.NullPointerException: null
        at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1853) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        ...


Indiscriminate copying of jar files is not going to help you.
Did you know that those 4 jar files provide you JSP (no JSTL) and will operate in the JSP spec/standard mode of Java 6? Just like Jetty 6.
Again, use Maven (or Grails) to obtain the correct jars, and then configure your desired environment correctly for Java 8 support.

 

~~~~~~~~~~ Step 3 ~~~~~~~~~~


I got tired of guessing what jars my app needs, and decided on a simple brute force way to pull down everything:
    1) I deleted the 5 jetty jars described above from my app's lib directory
    2) I completely emptied my C:\Users\Sam\.m2\repository directory
    3) I downloaded the Embedded Jetty w/ JSP Support project
        https://github.com/jetty-project/embedded-jetty-jsp
    4) I built it (mvn clean package), started the server (mvn exec:exec), and verified that it worked in my browser (http://localhost:8080/)
    5) I copied every *.jar file from my C:\Users\Sam\.m2\repository directory (there are 100 of them!) into my app's lib directory

Step #5 is completely the wrong thing to do.
You now have many duplicate classes, from different versions of the same artifact.
You also now have many classes that are actually dangerous (from a security point of view) to run in production.
You also have all of the maven infrastructure (and 3rd party plugins) in your web server now.
Use Maven (or Grails) to get the appropriate set of jars that you need.

 

Running my code with these 100 jetty jars fails with a similar stack trace:
    2015-08-21T16:03:52.001-0400 WARN [qtp934275857-19] -
    org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:579) ~[apache-jsp-8.0.9.M3.jar:2.3]
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) ~[apache-jsp-8.0.9.M3.jar:2.3]
        ...
    Caused by: java.lang.NullPointerException: null
        at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515) ~[apache-jsp-8.0.9.M3.jar:2.3]
        at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1846) ~[apache-jsp-8.0.9.M3.jar:2.3]
        ...

This is probably essentially the same as Step 2 above: recall that Step 2 used jetty 9.3.2.v20150730, whereas the Embedded Jetty w/ JSP Support project still uses jetty-9.2.6.  So, that likely explains the different line numbers in the stack traces.

You are still using the JSP spec mandated Java 6 support.
The Eclipse JDT compiler is still in use.
Switch to using JavaC.
 


~~~~~~~~~~ Future work ~~~~~~~~~~


My conclusion after Step 3 is that I cannot be missing something on my classpath at this point.


 

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.
Its identical to what you are describing.
Why they didn't use this forum, or stackoverflow, i cannot comprehend.

 

    --this link, which reports what looks like the same problem, claims to have a solution, but hides it behind subscription access:
        https://access.redhat.com/solutions/315013  

This one isn't related to your problem.
This is a configuration issue in jboss.

 
    --this link, which reports what looks like the same problem, and whose solution was to correct a typo in a .tld file:
        http://www.coderanch.com/t/614308/JSP/java/EL-function

This one was a mistake in their tld definition.
Once fixed, it started to work for them.
 


The solution in that final link above suggests that there is some bug in my code.

I do not have any .tld files, so the precise solution there is not relevant for me.

I quickly inspected my .jsp files, and see nothing obviously wrong.  Furthermore, I note that the .jsp files all worked under jetty 6.

SO, DOES ANYONE HAVE ANY SUGGESTIONS FOR WHERE I CAN LOOK TO DEBUG THIS?


Most important recommendations:

  1. Don't flail.
  2. Understand the problem.
  3. Use Maven (or grails) to get the correct set of Jars that *you* need for your project.
  4. Don't include the eclipse jdt jar in your project (use exclusions with maven/grails)
  5. Look at the code for github.com/jetty-project/embedded-jetty-jsp
    1. Configure for JavaC
    2. Setup context Attributes
    3. Setup InstanceManager
    4. Setup JettyJasperInitializer
    5. (and more, see the code)

Good luck,
- Joakim

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: embedded jetty 9 JSP: NullPointerException in org.apache.jasper.compiler.Validator

Barbara Tuchman
In reply to this post by Barbara Tuchman
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).

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: embedded jetty 9 JSP: NullPointerException in org.apache.jasper.compiler.Validator

Jan Bartel
Barbara,

To upgrade to jetty-9, follow the example of a single embedded webapp that uses jsp here: https://github.com/eclipse/jetty.project/blob/master/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebAppWithJsp.java

That maven project will list all necessary dependencies (actually there's probably a few extra in there, but it will get you going) by doing mvn dependency:tree.

If your jsps use java8-isms then you will need to redefine the JspServlet in your web.xml and set the init params "compilerSourceVM" and "compilerTargetVM" to "1.8" (the default in jetty-9 is "1.7").

Alternatively, it may be simpler for you to just precompile your jsps. You can use either the jetty-jspc-maven plugin (see https://www.eclipse.org/jetty/documentation/current/configuring-jsp.html#d0e6586)  to do this or you could write an ant build script to do it (google for info).

Jan

On 27 August 2015 at 10:45, Barbara Tuchman <[hidden email]> wrote:
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).

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <[hidden email]>
www.webtide.com
Expert assistance from the creators of Jetty and CometD


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users