So, it turns out the SMAP was causing my Java 8 compiler issues. When I added that suppressSmap = true, it successfully compiled the JSP using Java 8, and the lambda expression in my JSP works. Like you said, some kind of problem there that will need to be address eventually. Not sure what it is.
Last night I had compilerSourceVM and compilerTargetVM set to 1.8, "compiler" set to "modern", and tools.jar, ant.jar and ant-launcher.jar all on my classpath, and I was still getting the warning "org.apache.jasper.compiler.JDTCompiler generateClass WARNING: Unknown source VM 1.8 ignored." I promise :-). If I made just one more change, setting "compilerClassName" to the AntCompiler class, it stopped using the Eclipse compiler and I was instead getting an error "Unknown tag: 18." That error went away if I removed the lambda expression from my JSP, so I (incorrectly) assumed the Ant compiler didn't like Java 8 syntax. Turns out it was the SMAP that was causing that problem. This morning the only thing I changed was to add the suppressSmap = true and it started compiling. However, now I take off the compilerClassName parameter and it still works. Perhaps I've just been looking at this too long. I can't duplicate the behavior I was seeing last night anymore... Oh, well. It works. For everyone's future reference, this is everything that's necessary to compile JSPs in Java 8 in Tomcat 8: 1) Add to JSP servlet in conf\web.xml: <init-param> <param-name>compiler</param-name> <param-value>modern</param-value> </init-param> <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> <init-param> <param-name>suppressSmap</param-name> <param-value>true</param-value> </init-param> 2) Create setenv.bat (or setenv.sh, depending on your OS): set "CLASSPATH=/path/to/jdk/tools.jar;/path/to/ant/ant.jar;/path/to/ant/ant-launcher.jar" Interesting problem I'd welcome feedback on: I have an OS environmental variable JAVA_HOME set to C:\Program Files\Java\jdk1.8 (so, JAVA_HOME is set to the JDK home). My belief was that I SHOULD be able to leave off the tools.jar. However, that does not work. C:\Users\Nicholas>echo %JRE_HOME% %JRE_HOME% C:\Users\Nicholas>echo %JAVA_HOME% C:\Program Files\Java\jdk1.8 When starting, catalina.bat output says "Using JRE_HOME: "C:\Program Files\Java\jdk1.8"," so it's right there, and it has to be getting it from JAVA_HOME since JRE_HOME isn't set. However, upon first access of a JSP: org.apache.jasper.JasperException: Unable to compile class for JSP root cause Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\Program Files\Java\jdk1.8\jre" Why (and how) is the JAVA_HOME getting changed to the JRE? *scratches head* N -----Original Message----- From: Mark Thomas [mailto:ma...@apache.org] Sent: Tuesday, January 22, 2013 6:14 PM To: Tomcat Developers List Subject: Re: Compiling JSPs with JDK 1.8 in Tomcat 8 On 22/01/2013 22:40, Williams, Nick wrote: > As you can see from my testing and comment in bug 54461 > (https://issues.apache.org/bugzilla/show_bug.cgi?id=54461), after much > effort I discovered that "complier" is indeed a parameter, but so is > "compilerClassName." In order to use anything other than the Eclipse > JDT compiler, "compilerClassName" must be set to the class name of an > alternative org.apache.jasper.compiler.Compiler That statement is not correct. > The only other implementation at the moment is > org.apache.jasper.compiler.AntCompiler. The "compiler" parameter ONLY > affects the AntCompiler compiler right now, and is ignored if the > JDTCompiler is in use. (No matter what I set "compiler" to, I get > "org.apache.jasper.compiler.JDTCompiler generateClass WARNING: > Unknown source VM 1.8 ignored" warnings UNLESS I also set > compilerClassName to AntCompiler.) Again, those statements are incorrect. You are doing something wrong. See org.apache.jasper.JspCompilationContext#createCompiler() > That aside, my original problem is still unanswered. It appears > AntCompiler, like JDTCompiler, still uses some compiler other than the > JDK's built-in javac compiler. Whether I specify "classic," > "modern," or "extJavac" as the "compiler" for AntCompiler, I get > syntax errors for the lambda expression in my JSP. The same lambda > expression compiles fine in my JDK compiler. That first statement is also not correct. Ant uses whichever compiler you tell it to use via the compiler init parameter. > So, is there any way to use the JDK compiler to compile JSPs? Yes. The docs [1] cover what you need to do to use javac. To summarise: - set compiler init parameter for the JSP servlet to modern (or any other value from the Ant docs) in $CATALINA_BASE/conf/web.xml - remove $CATALINA_HOME/ecj-*.jar - copy ant.jar and ant-launcher.jar to $CATALINA_HOME/lib >From your description you may have missed some of those steps. You may also need to copy tools.jar from your Java 8 install to $CATALINA_HOME/lib. There will be an error message in the logs if tools.jar is not on the classpath. I didn't check if this was a Java 8 quirk or required for all Java versions. I suspect the latter in which case it is worth adding to the docs as not everyone reads error messages that carefully. > Or, am > I stuck compiling JSPs at Java 7 until either Eclipse or Ant starts > supporting Java 8? Ant already supports Java 8. This is clearly documented in the Ant docs for the javac task. There are a few additional changes you'll need to use Java 8. - set the compilerSourceVM and compilerTargetVM JSP init params to 1.8 (again this is documented in [1]) - set the suppressSmap JSP init param to false Java 8 doesn't like something about the JSP debug info. I'm not sure what the root cause is here (Tomcat bug, Java bug or new Java 8 feature that needs to be supported). Mark [1] http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org This e-mail may contain privileged or confidential information. If you are not the intended recipient: (1) you may not disclose, use, distribute, copy or rely upon this message or attachment(s); and (2) please notify the sender by reply e-mail, and then delete this message and its attachment(s). Underwriters Laboratories Inc. and its affiliates disclaim all liability for any errors, omissions, corruption or virus in this message or any attachments. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org