自定义标记库导致“PWC6033:无法编译 JSP 类”

发布于 2024-09-09 01:23:59 字数 1888 浏览 1 评论 0原文

当我尝试在我的 web 应用程序中使用自定义标记库时,它无法在 OS X(或 Windows)、使用 Eclipse 和 Run Jetty Run 上运行。当我对文件进行 WAR 并在运行 apache-tomcat-6.0.20 的 Linux 服务器上运行它们时,没有问题。我正在使用第 3 方自定义标签库,在这两种环境中都没有问题。

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)
 ...

自定义 taglib tld 看起来像

<?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>

和标签处理程序

package com.test;

import javax.servlet.jsp.tagext.TagSupport;

public class CustomTag extends TagSupport {

 private static final long serialVersionUID = 1L;

}

最后是 temp.jsp

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

我认为我的 taglib 定义/配置是正确的,因为部署到 tomcat 时整个事情都可以工作,但我一整天都在尝试让这项工作在 Jetty 中工作没有用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无畏 2024-09-16 01:23:59

太烦人了!!!我希望上帝能有人找到这个,这可以节省他们我浪费在寻找解决方案上的所有时间。我相信这是 Jetty 的问题。

我在 com 包中还有一个 Test 类。因此,无论出于何种原因,Jetty 都会寻找 com.test.CustomTag 并最终寻找可能在 com.Test 内部的内部类?无论如何,将 CustomTag 移动到另一个包(或者移动或重命名 com.Test)可以解决该问题。

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.

女皇必胜 2024-09-16 01:23:59

得到了解决方案。虽然我的 eclipse 在编译时没有显示错误。 Jetty 运行时,没有找到我添加的新类属性。因为maven还没有生成它。

我运行了这两个命令,之后一切都很好。
1.mvn清理
2. mvn安装-DskipTests

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

浅笑依然 2024-09-16 01:23:59

我也有同样的问题。
Jetty 但自定义标记文件(无标记库)

由于 Tyler 的帖子(2010 年 7 月 10 日 0:45),我将放弃这里。我可能会向码头的人群陈述我的情况。我无法将自定义标签移动到另一个包,因为它是一个标签文件并且没有声明包。

在 Eclipse 中它工作得很好。所有 Junit 测试都以绿色运行。 PWC6033 的“mvn 测试”失败,但没有进一步的详细信息。我只能猜测标记文件在部署到服务器时显然运行正确。

如果 jetty/maven 没有正确解析导入,那么对我来说这听起来像是一个错误。

为了完整起见,这里是我的标记文件,位于 /WEB-INF/tags/ognl.tag

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

其中 WebUtils 采用 HttpServletRequest 来获取属性值和另一个参数,该参数将一些内容打印到标准输出中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文