Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to compile class for JSP #1303

Closed
bnortman opened this issue Dec 30, 2016 · 21 comments · Fixed by #1311
Closed

Unable to compile class for JSP #1303

bnortman opened this issue Dec 30, 2016 · 21 comments · Fixed by #1311

Comments

@bnortman
Copy link

HTTP Status 500 - Unable to compile class for JSP:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 55 in the jsp file: /menu.jspf
'<>' operator is not allowed for source level below 1.7
52: ProjectHelper ph = ProjectHelper.getInstance(cfg);
53: Set projects = ph.getAllProjects();
54: if (projects == null) {
55: projects = new TreeSet<>();
56: }
57: int projectsSize = ph.getAllUngrouped().size();
58: if (ph.getGroups().size() > 0 && ph.getAllUngrouped().size() > 0)

An error occurred at line: 64 in the jsp file: /menu.jspf
'<>' operator is not allowed for source level below 1.7
61: projectsSize++;
62: projectsSize += ph.getAllGrouped(group).size();
63: }
64: TreeMap<String, String> pMap = new TreeMap<>();
65: QueryBuilder queryParams = cfg.getQueryBuilder();
66: if (projects.size() != 0) {
67: for (Project p : projects) {

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:104)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:490)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:379)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.opensolaris.opengrok.web.AuthorizationFilter.doFilter(AuthorizationFilter.java:60)

@bnortman
Copy link
Author

Tomcat is running on Oracle Java 8

tomcat7 22236 1 11 02:50 ? 00:00:17 /usr/lib/jvm/java-8-oracle/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.endorsed.dirs=/usr/share/tomcat7/endorsed -classpath /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -Djava.io.tmpdir=/tmp/tomcat7-tomcat7-tmp org.apache.catalina.startup.Bootstrap start

@vladak
Copy link
Member

vladak commented Dec 30, 2016

Oooks like you are compiling with jsva older than 1.8.

We should check for java version in early stages of build.

@tulinkry
Copy link
Contributor

Only Tomcat8 + java8

@bnortman
Copy link
Author

Java is 1.8 for compile using ANT and running on Java 1.8. Both Oracle instance. I update the a couple lines like

projects = new TreeSet<>();
to
projects = new TreeSet<String>();

and now everything works.

@bnortman
Copy link
Author

bnortman commented Jan 3, 2017

I just forked the code and updated the file to be more compatible.

bnortman@43a7baf

@vladak
Copy link
Member

vladak commented Jan 4, 2017

Let's keep this open to track the addition of Java version check for ant/maven.

@vladak vladak changed the title Unable to compile class for JSP check Java version when compiling and bail out if unsupported Jan 4, 2017
@vladak vladak self-assigned this Jan 4, 2017
@vladak vladak changed the title check Java version when compiling and bail out if unsupported Unable to compile class for JSP Jan 4, 2017
@vladak
Copy link
Member

vladak commented Jan 4, 2017

Actually, ant/maven check will not help here - this is about JSP compilation in Tomcat, sorry for the confusion. Not sure if it is possible to check Java version in Tomcat when deploying the war.

Still, this looks like Tomcat misconfiguration. Even though it seems to be running Java 8, it tries to compile with Java 7.

@vladak
Copy link
Member

vladak commented Jan 4, 2017

Maybe you could check all available Java versions on the machine and if Java 7 (JDK or JRE) is installed, try to uninstall, restart Tomcat and see what happens (with the original unmodified files containing the diamond operator).

@tulinkry
Copy link
Contributor

tulinkry commented Jan 4, 2017

Exactly my thoughts, this is not compiled with java 8.

@bnortman
Copy link
Author

bnortman commented Jan 4, 2017

I just re-run Ant in verbose mode

and got Java-8, is there any other settings I should look for? I got it working on my fork

Apache Ant(TM) version 1.9.6 compiled on July 8 2015
Trying the default build file: build.xml
Buildfile: /home/procon/Dev2/OpenGrok-Groovy/build.xml
Detected Java version: 1.8 in: /usr/lib/jvm/java-8-oracle/jre
Detected OS: Linux
parsing buildfile /home/procon/Dev2/OpenGrok-Groovy/build.xml with URI = file:/home/procon/Dev2/OpenGrok-Groovy/build.xml
Project base dir set to: /home/procon/Dev2/OpenGrok-Groovy
parsing buildfile jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
[property] Loading /home/procon/config/ant/OpenGrok.properties
[property] Unable to find property file: /home/procon/config/ant/OpenGrok.properties
[property] Loading /home/procon/config/ant/global.properties
[property] Unable to find property file: /home/procon/config/ant/global.properties

@vladak vladak removed the enhancement label Jan 4, 2017
@vladak
Copy link
Member

vladak commented Jan 4, 2017

Is there some other stuff under /usr/lib/jvm/ ?

Also, what Tomcat 7 version are you running exactly ?

@vladak
Copy link
Member

vladak commented Jan 4, 2017

Any chance of trying Tomcat 8 ?

@vladak
Copy link
Member

vladak commented Jan 4, 2017

Thinking aloud: I wonder if there is a way how to check Tomcat version (and incidentally Java version the Tomcat is using) from within the webapp when it is being deployed.

@bnortman
Copy link
Author

bnortman commented Jan 4, 2017

/usr/share/tomcat7/bin @ IRVOpenGrok(procon): ./catalina.sh version
Using CATALINA_BASE: /usr/share/tomcat7
Using CATALINA_HOME: /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME: /usr/lib/jvm/java-8-oracle
Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.68 (Ubuntu)
Server built: Jun 27 2016 18:13:17 UTC
Server number: 7.0.68.0
OS Name: Linux
OS Version: 4.2.0-27-generic
Architecture: amd64
JVM Version: 1.8.0_111-b14

@vladak
Copy link
Member

vladak commented Jan 4, 2017

Okay. I was asking because saw some reports of Tomcat 7 not working properly with Java 8 up to some minor version (7.0.50). Anyway. your safest bet is to try Tomcat 8.

@vladak
Copy link
Member

vladak commented Jan 4, 2017

Additional measure would be to tune the jsp servlet configuration in conf/web.xml, in particular set the compilerSourceVM and compilerTargetVM config parameters to 1.8.

@bnortman
Copy link
Author

bnortman commented Jan 4, 2017

I tried getting Tomcat8 up but I have too many configurations to play with, so I just forked and updated the one file and recompiled. Seems to work great now. Plus I wanted to add support for Groovy via the Java Analyzer. https://github.com/bnortman/OpenGrok-Groovy

@vladak
Copy link
Member

vladak commented Jan 5, 2017

I was hoping to get to the bottom of this. Clearly, the Java version Tomcat is running under does not have direct bearing on the JSP compiler in the same Tomcat. Either, the compiler somehow prefers Java 1.7 which is present on the system (otherwise there would be no complaint about the diamond operator which is native in Java 1.8) or it is configured to use Java 1.7 directly in the jsp servlet configuration (that deals with *.jsp files).

As for the Groovy support, feel free to create pull req.

@suburbanOrfeus
Copy link

Hello,
I had a similar issue with the JSP compiler when using GlassFish4:

HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

PWC6199: Generated servlet error:
source value 1.5 is obsolete and will be removed in a future release

PWC6199: Generated servlet error:
target value 1.5 is obsolete and will be removed in a future release

PWC6199: Generated servlet error:
To suppress warnings about obsolete options, use -Xlint:-options.

PWC6197: An error occurred at line: 48 in the jsp file: /menu.jspf
PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

I first purged everything that wasn't java-8-oracle but that was not sufficient!

$ java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

$ sudo update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode

  • 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode

I solved the JSP compile issues by adding the following to glassfish4/glassfish/domains/domain1/config/default-web.xml

    <init-param>
      <param-name>compilerSourceVM</param-name>
      <param-value>1.8</param-value>
    </init-param>
    <init-param>
      <param-name>compilerTargetVM</param-name>
      <param-value>1.8</param-value>
    </init-param>

@tulinkry
Copy link
Contributor

tulinkry commented Oct 6, 2018

It's possible to override the default tomcat7 1.6 value with 1.7 (or 1.8) in our web.xml.

    <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>compilerSourceVM</param-name>
            <param-value>1.7</param-value>
        </init-param>
        <init-param>
            <param-name>compilerTargetVM</param-name>
            <param-value>1.7</param-value>
        </init-param>
    </servlet>

@bahaazenhom
Copy link

I was getting the same error, I solved it with just changing an ArrayList declaration from this "new ArrayList<>();" to this "new ArrayList(); "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants