简体   繁体   English

导入javax.servlet和org.hibernate无法解析-Ubuntu 12.04上的Eclipse Kepler

[英]The import javax.servlet and org.hibernate cannot be resolved - Eclipse Kepler on Ubuntu 12.04

I installed latest version of Eclipse Java EE Kepler version. 我安装了最新版本的Eclipse Java EE Kepler版本。
And tried to write easy program on Java. 并尝试在Java上编写简单的程序。 But when I make some import statements I catch message: 但是,当我进行一些导入语句时,会捕获以下消息:

The import xxx cannot be resolved.

It doesn't work for - javax.servlet, org.hibernate, org.springframework, org.junit . 它不适用于javax.servlet, org.hibernate, org.springframework, org.junit

I don't know why exactly this happen. 我不知道为什么会这样。 I'm using 1.7 JDK + tomcat 7. Current OS is Ubuntu 12.04. 我正在使用1.7 JDK + tomcat7。当前操作系统是Ubuntu 12.04。
I added tomcat 7 to eclipse, and SpringSource Tool Suite for Eclipse Kepler. 我在eclipse中添加了tomcat 7,并在Eclipse Kepler中添加了SpringSource Tool Suite。

How to solve this trouble? 如何解决这个麻烦?

java.servlet, org.hibernate, etc. are not part of the JDK. java.servlet,org.hibernate等不是JDK的一部分。 They're external libraries (jars) that must be added to the classpath. 它们是必须添加到类路径中的外部库(jar)。

As mentioned in the other question you need to either to download the jar files manually and add them to the class path, or use a build tool such as maven it will help you download the dependencies you will specify in the pom.xml file and add them to the classpath. 如另一个问题所述,您需要手动下载jar文件并将其添加到类路径,或者使用诸如maven之类的构建工具,它将帮助您下载将在pom.xml文件中指定的依赖项并添加他们到类路径。 And more to that you can run build and package in a war file for deploying your application into tomcat 除此之外,您还可以在war文件中运行构建和打包,以将应用程序部署到tomcat中

For hibernate, be sure you added spring-orm in your pom.xml file 对于休眠,请确保在pom.xml文件中添加了spring-orm

 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.2.5.RELEASE</version>
    </dependency>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM