custom taglibs cause “PWC6033: Unable to compile class for JSP”

江枫思渺然 提交于 2021-01-27 11:28:46

问题


When I try to use custom taglibs in my webapp it doesn't work on OS X (or Windows), using Eclipse, and Run Jetty Run. When I WAR up the files and run them on my linux server running apache-tomcat-6.0.20, there is no problem. I'm using 3rd party custom taglibs without problems in both environments.

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

PWC6197: An error occurred at line: 6 in the jsp file: /temp.jsp
PWC6199: Generated servlet error:
com.test cannot be resolved to a type
 at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:107)
 at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:280)
 at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:350)
 at org.apache.jasper.compiler.Compiler.compile(Compiler.java:411)
 ...

The custom taglib tld looks like

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC 
 "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
 "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
 <tlib-version>1.0</tlib-version>
 <jsp-version>2.0</jsp-version>
 <short-name>test</short-name>
 <uri>http://test.com/test.tld</uri>
 <description>Test</description>

 <tag>
  <name>custom</name>
  <tag-class>com.test.CustomTag</tag-class>
  <body-content>empty</body-content>
  <description>Custom tag</description>
 </tag>
</taglib>

And the Tag handler

package com.test;

import javax.servlet.jsp.tagext.TagSupport;

public class CustomTag extends TagSupport {

 private static final long serialVersionUID = 1L;

}

And finally temp.jsp

<%@ taglib uri="http://test.com/test.tld" prefix="test" %>
Hi
<test:custom/>

I think my taglib definition / configuration is correct since the whole thing works when deployed to tomcat, but I've been trying things all day to make this work in Jetty to no avail.


回答1:


SOOOOOOOOOOO annoying!!!! I hope to GOD that someone finds this and it saves them all the time I wasted trying to figure out the solution. I believe this is a problem with Jetty.

I also had a class Test in the com package. So for whatever reason, Jetty would go looking for com.test.CustomTag and end up looking for an inner class maybe inside of com.Test? In any case, moving CustomTag to another package (or moving or renaming com.Test) fixed the issue.




回答2:


Got the solution. Though My eclipse did not show error when i compiled. Jetty when ran, did not find the new class attribute that i added. As maven had not yet generated it.

I ran these 2 commands and things were fine afterwards. 1. mvn clean 2. mvn install -DskipTests




回答3:


I am having somewhat the same problem. Jetty but custom tagfiles (no taglib)

I will give up here due to Tyler's post (Jul 10 '10 at 0:45). I might state my case to the jetty crowd. I cannot move my custom tag to another package because it is a tagfile and does not declare a package.

In Eclipse it works fine. All Junit Tests run green. 'mvn test' fails with PWC6033 but no further detailed information. I just could guess the tagfile which obviously runs correct when deployed to a server.

If the imports are not correctly resolved by jetty/maven then it sounds like a bug to me.

For completeness, here is my tagfile at /WEB-INF/tags/ognl.tag

<%@tag import="de.mypackage.WebUtils"
%><%@tag body-content="empty"
%><%@attribute name="value" required="true"
%><%=WebUtils.ognl(request, value)%>

Where WebUtils takes the HttpServletRequest in order to fetch an attribute value and another parameter which does print some stuff into standard out.



来源:https://stackoverflow.com/questions/3217159/custom-taglibs-cause-pwc6033-unable-to-compile-class-for-jsp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!