在 Java 构建路径上找不到超类“javax.servlet.http.HttpServlet”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26936848/
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
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
提问by user3362080
I'm a beginner and learning spring and hibernate (utilizing maven in project)and came across this problem and got stuck here. tried finding solution but ended up no where. Please help. thanks a lot
我是一名初学者,正在学习 spring 和 hibernate(在项目中使用 maven)并遇到了这个问题并被困在这里。试图找到解决方案,但最终无处可去。请帮忙。多谢
Error: "Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
错误:“找不到“ http://java.sun.com/jsp/jstl/core”的标签库描述符
Code:
代码:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
Tried the solutions given in The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build PathHow do I import the javax.servlet API in my Eclipse project?
尝试了Java Build Path 中未找到超类“javax.servlet.http.HttpServlet”中给出的解决方案如何在我的 Eclipse 项目中导入 javax.servlet API?
The error still present
错误仍然存在
pom.xml
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.journaldev.spring</groupId>
<artifactId>SpringMVCHibernate</artifactId>
<name>SpringMVCHibernate</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>4.0.3.RELEASE</org.springframework-version>
<org.aspectj-version>1.7.4</org.aspectj-version>
<org.slf4j-version>1.7.5</org.slf4j-version>
<hibernate.version>4.3.5.Final</hibernate.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Apache Commons DBCP -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- Spring ORM -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
采纳答案by adarsh hegde
Adding the tomcat server in the server runtime will do the job :
在服务器运行时添加 tomcat 服务器将完成这项工作:
Project Properties-> Java Build Path-> Add Library -> Select "Server Runtime" from the list-> Next->Select "Apache Tomcat"-> Finish
回答by Joshnee
Adding below dependency in pom.xml, worked for me.
在 pom.xml 中添加以下依赖项,对我有用。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
回答by G V Arun Kumar
I too received the same error as quoted below:
我也收到了与下面引用的相同的错误:
The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path.
在 Java 构建路径中找不到超类“javax.servlet.http.HttpServlet”。
I followed these steps to resolve the issue:
我按照以下步骤解决了这个问题:
- Right Click on Project
- Select Properties
- Select Project Facets
- Select Apache Tomcat as Runtime server
- Click OK
- 右键单击项目
- 选择属性
- 选择项目构面
- 选择 Apache Tomcat 作为运行时服务器
- 单击确定
回答by Dhruv Kadia
add servlet-api jar file which is present in the lib folder under tomcat folder. You can do this as follows Project -> properties -> java build path -> under libraries click add external jars after that go to project -> clean -> build all. this worked for me.
添加 servlet-api jar 文件,该文件位于 tomcat 文件夹下的 lib 文件夹中。您可以按以下方式执行此操作 Project -> properties -> java build path -> 在库下单击 add external jars 然后转到 project -> clean -> build all。这对我有用。
回答by ILAIYARAJA
Add servlet-api.jar file which is present in the lib folder under tomcat folder. You can do this using the following steps:
添加 servlet-api.jar 文件,该文件位于 tomcat 文件夹下的 lib 文件夹中。您可以使用以下步骤执行此操作:
1.Select project properties
2.Select Java Build Path
3.Select Libraries
4.Select External Jars
5.Select servlet-api.jar
6. Apply & Ok.
1.
选择项目属性2. 选择 Java 构建路径
3. 选择库
4.选择外部罐子
5. 选择 servlet-api.jar
6. 应用并确定。
The issue should be resolved after these steps.
执行这些步骤后,问题应该得到解决。
回答by engtuncay
for maven project , you should add this dependency
对于 maven 项目,您应该添加此依赖项
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
回答by MAC
I came across the same issue. I tried adding the server in "Server Runtime" but unfortunately that didn't work for me.
我遇到了同样的问题。我尝试在“服务器运行时”中添加服务器,但不幸的是这对我不起作用。
What worked for me is, I added javax.servlet-api-3.0.1.jar
file in build path. On the other hand If It's a Maven project add dependency for this jar file. This would definitely work.
对我有用的是,我javax.servlet-api-3.0.1.jar
在构建路径中添加了文件。另一方面,如果它是一个 Maven 项目,请为此 jar 文件添加依赖项。这肯定会奏效。
回答by harun ugur
Adding the Tomcat server in the server runtime will do the job:
在服务器运行时添加 Tomcat 服务器将完成这项工作:
Right click your project and than;
右键单击您的项目,然后;
Project properties → Target Runtimes → Select/Check "Apache Tomcat" → Finish.
项目属性→目标运行时→选择/检查“Apache Tomcat”→完成。
回答by James Oravec
I had this same issue and a couple others being reported for a existing maven project.
我遇到了同样的问题,并且针对现有的 Maven 项目报告了其他几个问题。
I had the proper dependencies in place and I could see the jar under maven dependencies, however the project was improperly brought into eclipse.
我有适当的依赖项,我可以在 Maven 依赖项下看到 jar,但是该项目被错误地引入了 Eclipse。
I ended up having to delete the project, clone from git again then do an import of the project as an existing maven project.
我最终不得不删除该项目,再次从 git 克隆,然后将该项目作为现有的 maven 项目导入。
This solved the issue in this thread and several others issues I was having. More details on solution can be found here: Maven Project in Eclipse `org.springframework cannot be resolved to a type` from target path
这解决了该线程中的问题以及我遇到的其他几个问题。可以在此处找到有关解决方案的更多详细信息:Eclipse `org.springframework 中的 Maven 项目无法解析为目标路径中的类型`
回答by cyberdemon
Always check if your java filesare in src/main/javaand not on some other directorypath.
始终检查您的java 文件是否在src/main/java 中,而不是在其他目录路径中。