Tomcat 6 中的 jar 文件放在哪里?
我无法让 JSP 页面加载 jar 文件中的 Java 类。我收到的消息似乎表明类未找到异常:
Jan 6, 2011 12:21:45 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 72 in the jsp file: /xmlloader.jsp
FactArray cannot be resolved to a type
69: sourceType = "1";
70: }
71:
72: FactArray fa = new FactArray();
73: Fact f;
74:
75: /***********************/
类型 FactArray
是 myjar.jar 中存在的 com.mypackage.fact.FactArray 包中的类之一。 myjar.jar 是一个单独的 Java 项目(使用 NetBeans,但我认为这不相关)。
我将该包包含在 JSP 中,如下所示:
<%@ page import="com.mypackage.fact.*" %>
我将网站和 JSP 作为 WAR 文件部署到 Tomcat 6 中。我将 myjar.jar 包含在 WEB-INF/lib 的 WAR 中,但这不起作用。我尝试将 myjar.jar 放入 tomcat/lib 文件夹中,但这也不起作用。
我在更改之间多次退回服务器。我在这里读到了一大堆问题,上面写着“将其放入 WEB-INF/lib”,但这不起作用,所以我问自己的问题。
我需要将常见 JAR 文件放在哪里以便 Tomcat 获取它们?
I am having trouble getting my JSP page to load a Java class which is in a jar file. The message I get appears to indicate a class not found exception:
Jan 6, 2011 12:21:45 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 72 in the jsp file: /xmlloader.jsp
FactArray cannot be resolved to a type
69: sourceType = "1";
70: }
71:
72: FactArray fa = new FactArray();
73: Fact f;
74:
75: /***********************/
The Type FactArray
is one of my classes in a package com.mypackage.fact.FactArray which exists in myjar.jar. myjar.jar is a separate Java project (using NetBeans, but I don't think that's relevant).
I include the package in my JSP as follows:
<%@ page import="com.mypackage.fact.*" %>
I deploy my web site and JSPs into Tomcat 6 as a WAR file. I include myjar.jar in that WAR in WEB-INF/lib but that doesn't work. I tried putting myjar.jar in my tomcat/lib folder, but that doesn't work either.
I have bounced the server several times between changes. I have read a whole bunch of questions on here which say "put it in WEB-INF/lib" but that isn't working, so I'm asking my own question.
Where do I need to put common JAR files so they get picked up by Tomcat?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
放入已部署的 web 应用程序的
/WEB-INF/lib
文件夹中应该可以工作。如果这不起作用,则可能的原因是:
不相关对于这个问题,使用scriptlet并不是最佳实践。考虑一个 servlet。
Putting in
/WEB-INF/lib
folder of the deployed webapp should work.If that doesn't work, then the possible causes are:
Unrelated to the problem, using scriptlets is not the best practice. Consider a servlet.
确保代码中有正确的导入语句;根据您设置环境的方式,将 jar 放在 webapps/ROOT/lib 中
Make sure you have the correct import statements in the code; depending on how you set up your env, place the jars in the webapps/ROOT/lib