定制类装入器的JSP编译错误 [英] JSP compilation error with custom classloader

查看:85
本文介绍了定制类装入器的JSP编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在tomcat(7.0.55)中有一个自定义WebappClassLoader,它在server.xml中配置为

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>

它已经加载并且一切都很好,但是当我打开一个JSP来加载org.test.User类时,该类不在WEB-INF/classes下,但是可以通过DynamicClassLoader加载,我得到此错误:

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

因此,我进行了一些调试,并在每个loadClass调用中检查是否已加载我的类,是的:就在此错误消息之前,我看到了我的调试消息:

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

因此,看来jsp编译器要求提供User类.但是,真正的怪异之处在于,如果我在日食之外执行它,那么一切都会正常进行!当然,除了错误消息外,输出看起来相同.我仔细检查了由eclipse和我的文件生成的配置文件,但没有发现任何区别.

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.

您有什么想法吗?为什么它可以在Eclipse中正常运行,而在正常" tomcat安装中却没有任何错误?如果您需要任何进一步的信息,请告诉我!预先感谢!

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!

推荐答案

JSP编译器有时很难处理可同时解析为package(目录)和class( .class文件).如果您的类是从JAR文件中加载的,请尝试从JAR文件中删除目录条目(当然,请保留.class文件).

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.

Eclipse与独立版本之间的差异可能与Eclipse使用的不同部署描述符有关.您可能想查看Eclipse在做什么……可能正在使用稍微不同的配置或打包策略.

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.

这篇关于定制类装入器的JSP编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆