简体   繁体   English

我在哪里把jar文件放在Tomcat 6中?

[英]Where do I put jar files in Tomcat 6?

I am having trouble getting my JSP page to load a Java class which is in a jar file. 我无法让我的JSP页面加载一个jar文件中的Java类。 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. Type FactArray是我的一个类com.mypackage.fact.FactArray中的一个类,它存在于myjar.jar中。 myjar.jar is a separate Java project (using NetBeans, but I don't think that's relevant). 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. 我将我的网站和JSP作为WAR文件部署到Tomcat 6中。 I include myjar.jar in that WAR in WEB-INF/lib but that doesn't work. 我在WEB-INF / lib中的WAR中包含myjar.jar,但这不起作用。 I tried putting myjar.jar in my tomcat/lib folder, but that doesn't work either. 我尝试将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选中?

Putting in /WEB-INF/lib folder of the deployed webapp should work. 放入已部署的webapp的/WEB-INF/lib文件夹应该可以正常工作。

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) JAR根本不包含所需的类(使用ZIP工具提取并验证)
  • 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. 与问题无关,使用scriptlet不是最佳实践。 Consider a servlet . 考虑一个servlet

Make sure you have the correct import statements in the code; 确保代码中包含正确的import语句; depending on how you set up your env, place the jars in the webapps/ROOT/lib 根据您设置env的方式,将jar放在webapps / ROOT / lib中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 -javaagent 添加到 Tomcat 6 服务器,我将它放在哪里以及以什么格式? - Adding -javaagent to Tomcat 6 server, where do I put it and in what format? 在何处放置JAR文件以避免冲突? - Where To Put JAR Files To Avoid Conflicts? 将jar文件放在存储库中的位置 - where to put jar files inside repository tomcat webapp - 我在哪里存储永久文件 - tomcat webapp - where do i store permanent files jar文件必须在运行时在哪里? 我正在使用netbeans - where do jar files have to be at runtime? I'm using netbeans 如何使用 Maven 将所有必需的 JAR 文件放在最终 JAR 文件内的库文件夹中? - How do I put all required JAR files in a library folder inside the final JAR file with Maven? 如何将要由java.io.FileReader读取的文件放在哪里? - Where do I put files to be read by java.io.FileReader? 在开发Web应用程序时,我应该在哪里放置外部JAR文件? - Where should I put external JAR files when developing a web app? 将i18n文件放在没有WEB-INF文件夹的实用程序jar中的位置 - Where to put i18n files in utility jar which has no WEB-INF folder JDBC驱动程序JAR文件应该驻留在具有数据源的Tomcat部署中的哪个位置? - Where should the JDBC driver JAR files reside on a Tomcat deployment with a datasource?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM