Tomcat 6 中的 jar 文件放在哪里?

发布于 2024-10-10 17:05:24 字数 994 浏览 4 评论 0原文

我无法让 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 技术交流群。

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

发布评论

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

评论(2

悲喜皆因你 2024-10-17 17:05:24

放入已部署的 web 应用程序的 /WEB-INF/lib 文件夹中应该可以工作。

如果这不起作用,则可能的原因是:

  • JAR 根本不包含所需的类(使用 ZIP 工具提取并验证)
  • 您的导入和/或类声明中有拼写错误(注意区分大小写!)

不相关对于这个问题,使用scriptlet并不是最佳实践。考虑一个 servlet

Putting in /WEB-INF/lib folder of the deployed webapp should work.

If that doesn't work, then the possible causes are:

  • The JAR doesn't contain the desired class at all (extract with ZIP tool and verify)
  • There's a typo in your import and/or class declaration (mind case sensitivity!)

Unrelated to the problem, using scriptlets is not the best practice. Consider a servlet.

殤城〤 2024-10-17 17:05:24

确保代码中有正确的导入语句;根据您设置环境的方式,将 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

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