eclipse - 无法加载 servlet-api.jar

标签 eclipse web-applications tomcat jar

我正在运行 Eclipse Indigo 3.7、Tomcat7、Spring MVC 框架 2.5.6。

在我的一个应用程序项目中,我收到以下错误消息:

nov. 22, 2011 9:06:30 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
Infos: validateJarFile(/home/pc/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SpringMVC/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

我读过,对于像我这样的 Web 应用程序项目,servlet-api.jar 不应包含在项目构建路径中;是对的吗?我应该把 servlet-api.jar 放在哪里,因为我的应用程序中有 servlet?

另外我想问一下:

我经常读到将 jar 文件放在 WEB-INF/lib 文件夹中,有时我读到将它们作为外部 Jar 包含在项目构建路径中,有时我读到同时执行这两个操作。

例如,我读过: -servlet-api.jar已经在Tomcat7/lib目录下,但还需要包含在项目路径中; -用于java的MySQL JDBC驱动程序必须包含在项目路径中,并复制到WEB-INF/lib和Tomcat7/lib目录中。

谁能告诉我真相并帮助我真正理解如何在 eclipse 项目中管理 «Jar librairies»?

非常感谢。

最佳答案

  • 我了解到,对于像我这样的 Web 应用程序项目,servlet-api.jar 不应包含在项目构建路径中;是对的吗?我应该把 servlet-api.jar 放在哪里,因为我的应用程序中有 servlet?

    Servlet containers (such as Tomcat)have the servlet JARs in the classpath. So your application WAR should exclude it.

  • 我经常读到将 jar 文件放在 WEB-INF/lib 文件夹中,有时我读到将它们作为外部 Jar 包含在项目构建路径中,有时我读到在同时。

    JARs referenced by your application are typically placed in WEB-INF/lib. Exceptions are things like servlet.jar. You will need them at compile time but will have to exclude them from the resulting WAR.

  • 我读到:-servlet-api.jar 已经在 Tomcat7/lib 目录中,但还需要包含在项目路径中; -用于java的MySQL JDBC驱动程序必须包含在项目路径中,并复制到WEB-INF/lib和Tomcat7/lib目录中。

    That is correct. To amplify the answer to previous question, you need these JARs are compile time so that you can compile. Some JARs -- like the servlet-api are provided by the servlet container.

  • 谁能告诉我真相并帮助我真正理解如何在 eclipse 项目中管理 «Jar librairies»?

    Build tools such as Maven help manage your project's external library dependencies with fine-grained control over when these dependencies are needed (compile time only, compile and test, at runtime, etc).

关于eclipse - 无法加载 servlet-api.jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8244964/

相关文章:

eclipse - Eclipse/Aptana IDE 下的 Tab 缩进

google-apps-script - 如何允许其他人访问由 Google Apps 脚本制作的网络应用程序?

java - 我无法让jsp执行SQL更新语句

java - servlet可以更改另一个域的cookie吗

c - 为什么 sourceTree 会自动推送具有本地更改的文件?

java - 使用 Android 开发卡在 Eclipse 中的模拟器屏幕上?

java - LDAP+ Java : How can I know my active directory's names

php - 显示存储在 MySQL 数据库 PHP 中的 PDF 文件

java - Jersey 2.x(非 Maven)在 Tomcat 服务器上运行时给出 404 错误

tomcat - 为什么传递依赖不包括我的最终 war ?