问题
I have a custom WebappClassLoader in tomcat (7.0.55) which is configured in the server.xml as
<Context allowCasualMultipartParsing="true">
<Loader loaderClass="org.project.system.core.classloader.DynamicClassLoader" />
</Context>
It's is loaded and everything is fine, but when I open a JSP which loads a class org.test.User which isn't under WEB-INF/classes, but loadable via my DynamicClassLoader I get this error:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 7 in the generated java file
Only a type can be imported. org.test.User resolves to a package
So, I did some debugging and was checking in each loadClass call if my class is loaded and yes: right before this error message I see my debug message:
Trying to load org.test.User found!
Trying to load org.test NOT FOUND!!
Trying to load org.test NOT FOUND!!
Trying to load org.apache.el.ExpressionFactoryImpl found!
Trying to load com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl found!
Trying to load com.sun.org.apache.xerces.internal.impl.dv.dtd.DTDDVFactoryImpl found!
Trying to load org.apache.el.ExpressionFactoryImpl found!
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 7 in the generated java file
Only a type can be imported. org.test.User resolves to a package
So it seems, that the jsp compiler asks for the User class. But the real weird thing is that if I execute it out of eclipse, everything is working! The output looks the same except for the error message, of course. I double checked the configuration files which are generated by eclipse and my ones but I saw no difference.
Do you have an idea what could be wrong? Why is it working without any error in eclipse but not in a "normal" tomcat installation? Please let me know if you need any further information! Thanks in advance!
回答1:
The JSP compiler sometimes has a tough time dealing with items in the classpath that can be resolved to both a package (directory) and a class (.class file). If your classes are being loaded from a JAR file, try to remove the directory entry from the JAR file (but leave the .class file, of course).
If the directories and classes are on the disk, you might have to suck it up and re-name either the package or the directory.
The difference in Eclipse versus standalone might have to do with the different deployment descriptor that Eclipse uses. You might want to check out what Eclipse is doing... there might be a slightly different configuration or packaging strategy in play.
来源:https://stackoverflow.com/questions/25944468/jsp-compilation-error-with-custom-classloader