3
votes

I'm running an embedded version of Jetty (7.6.14v20131031) that is part of an automated unit test which includes accessing JSPs. When I run the unit test in Eclipse it works perfectly but when I run from the maven command line I get class not found errors while compiling the JSP:

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

PWC6199: Generated servlet error: package javax.servlet does not exist

PWC6199: Generated servlet error: package javax.servlet.http does not exist

PWC6199: Generated servlet error: package javax.servlet.jsp does not exist

. . .

It also can't find any of the classes specific to this project. Its as if the JSP compiler isn't getting the classpath from surefire? Any help would be greatly appreaciated.

2

2 Answers

3
votes

I'm not totally sure WHY this is now working, but adding

-Dorg.apache.jasper.compiler.disablejsr199=true

to the maven command line fixes the problem

1
votes

Another workaround is to disable the maven manifest-only-jar.

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
      <useManifestOnlyJar>false</useManifestOnlyJar>
    </configuration>
  </plugin>
  ....
<plugin>

The default way to pass the classpath in maven tests seems to confuse the JSP compiler.

disablejsr199 that is used in the other answer will cause jetty to not use the compiler provided by Java but use a built-in version. This built-in compiler uses a different way to compute its classpath and seems to not have problems with the maven manifest-only-jar. The disadvantage is, that this built-in compiler needs to match your Java version. For instance using a Java 8 compiler in your project with an older version of jetty (that has only a Java 7 internal compiler) will lead to problems:

Jan 12, 2017 8:31:36 AM org.apache.jasper.compiler.JDTJavaCompiler$1 findType
SCHWERWIEGEND: Compilation error
org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
    at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:372)
    at org.apache.jasper.compiler.JDTJavaCompiler$1.findType(JDTJavaCompiler.java:358)
    at org.apache.jasper.compiler.JDTJavaCompiler$1.findType(JDTJavaCompiler.java:315)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:113)
    at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:168)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2469)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1006)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1258)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:539)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:763)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:468)
    at org.apache.jasper.compiler.JDTJavaCompiler.compile(JDTJavaCompiler.java:494)
    at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:384)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)

This can be avoided by this solution.