我正在使用 Eclipse 3.7 (STS),并在 IDE 中运行 Tomcat 7。我创建了一个新的 Dynamic Web 项目,并将一个 JSP 文件添加到 Web 内容根文件夹中。我可以运行 Tomcat 并从 Eclipse 中访问 JSP,没有任何问题。
我从用户库中向项目添加了一些第 3 方 JAR(我没有使用 Maven 或自动依赖管理)。在 JSP 中,我引用了项目 JAR 文件中的一个类,我可以毫无问题地对其进行编译,但是当我在 Tomcat 上部署时,JSP 会抛出 ClassNotFoundException。显然,Tomcat 无法从我的库设置中找到 JAR。我尝试为 Tomcat 服务器创建运行方式配置,并将类路径设置为与项目的类路径设置匹配,但仍然遇到相同的 classnotfound 问题。
我可以通过手动将所有项目 JAR 复制到 WEB-INF/lib 目录来解决这个问题,以便 web 应用程序可以找到所有依赖项,但这是荒谬的,我不希望这成为解决方案,因为这是维护噩梦。
我错过了什么吗?
I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
发布评论
评论(2)
在项目的属性中,转到“部署程序集”。在那里添加构建路径条目以及您手动添加为用户库的条目。它最终会出现在已部署的 WAR 的
/WEB-INF/lib
中。另请参阅:
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in
/WEB-INF/lib
of the deployed WAR.See also:
您需要将 jar 文件复制到 WEB-INF/lib 文件夹:这就是它们应该所在的位置。
Eclipse 应该为您提供生成包含所有依赖项的 WAR 文件的选项:我已经有一段时间没有使用 Web Tools,但无论如何,所有依赖项都必须位于 WEB-INF/lib 中,否则类加载器将无法加载找不到他们。
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.