在 Eclipse 构建路径中使用用户库时出现 ClassNotFoundException [英] ClassNotFoundException when using User Libraries in Eclipse build path
问题描述
我使用 Eclipse 3.7 (STS) 和在 IDE 中运行的 Tomcat 7.我创建了一个新的动态 Web 项目并将一个 JSP 文件添加到 Web 内容根文件夹.我可以毫无问题地运行 Tomcat 并从 Eclipse 中访问 JSP.
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.
我从用户库中向项目添加了一些 3rd 方 JAR(我没有使用 maven 或自动依赖管理).在 JSP 中,我从项目的 JAR 文件中引用了一个类,我可以毫无问题地编译它,但是当我在 Tomcat 上部署时,JSP 会抛出 ClassNotFoundException.显然,Tomcat 无法从我的库设置中找到 JAR.我尝试为 Tomcat 服务器创建一个运行方式配置,并将类路径设置为匹配项目的类路径设置,但我仍然遇到相同的 classnotfound 问题.
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.
我可以通过手动将所有项目 JAR 复制到 WEB-INF/lib 目录来解决这个问题,这样 webapp 就可以找到所有依赖项,但这是荒谬的,我不希望这是解决方案,因为它是维护的噩梦.
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.
我错过了什么吗?
推荐答案
在项目的属性中,转到 Deployment Assembly.在那里添加构建路径条目以及您手动添加为用户库的条目.它将最终出现在已部署 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.
这篇关于在 Eclipse 构建路径中使用用户库时出现 ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!