java Tomcat 6 中的 jar 文件应该放在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4619106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where do I put jar files in Tomcat 6?
提问by Simon
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:
我在让 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: /***********************/
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).
TypeFactArray
是我在 myjar.jar 中存在的包 com.mypackage.fact.FactArray 中的类之一。myjar.jar 是一个单独的 Java 项目(使用 NetBeans,但我认为这无关紧要)。
I include the package in my JSP as follows:
我将包包含在我的 JSP 中,如下所示:
<%@ 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.
我将我的网站和 JSP 作为 WAR 文件部署到 Tomcat 6 中。我在 WEB-INF/lib 中的那个 WAR 中包含 myjar.jar 但这不起作用。我尝试将 myjar.jar 放在我的 tomcat/lib 文件夹中,但这也不起作用。
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.
我在更改之间多次退回服务器。我在这里阅读了一大堆问题,上面写着“把它放在 WEB-INF/lib 中”,但这不起作用,所以我在问我自己的问题。
Where do I need to put common JAR files so they get picked up by Tomcat?
我需要在哪里放置常见的 JAR 文件,以便 Tomcat 获取它们?
回答by BalusC
Putting in /WEB-INF/lib
folder of the deployed webapp should work.
放入/WEB-INF/lib
已部署的 webapp 的文件夹中应该可以工作。
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!)
- JAR 根本不包含所需的类(使用 ZIP 工具提取并验证)
- 您的导入和/或类声明中存在拼写错误(注意区分大小写!)
Unrelated to the problem, using scriptletsis not the best practice. Consider a servlet.
与问题无关,使用scriptlet不是最佳实践。考虑一个servlet。
回答by user353829
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
确保代码中有正确的导入语句;根据您设置 env 的方式,将 jar 放在 webapps/ROOT/lib 中