eclipse helios:tomcat 项目 - jar 将不会被导出或发布。可能会导致运行时 ClassNotFoundExceptions
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4255826/
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
eclipse helios: tomcat project - jar will not be exported or published. runtime ClassNotFoundExceptions may result
提问by ufk
I'm using Eclipse Helios and I was wondering how can I add a library project to my folder that will be copied to the build directory where my compiled project resides.
我正在使用 Eclipse Helios,我想知道如何将库项目添加到我的文件夹中,该文件夹将被复制到我编译的项目所在的构建目录中。
currently I did the following:
目前我做了以下事情:
- created a lib directory in the root of my project
- copied the relevant jars to that dir
- My Project -> properties -> Java Build Path -> add jars and I added all the jars from that directory.
- 在我的项目的根目录中创建了一个 lib 目录
- 将相关的 jars 复制到该目录
- 我的项目 -> 属性 -> Java 构建路径 -> 添加 jar,我添加了该目录中的所有 jar。
after adding all the jars i got the following warning regarding each of the jar file:
添加所有 jar 后,我收到有关每个 jar 文件的以下警告:
jar will not be exported or published. runtime ClassNotFoundExceptions may result
first of all how can I add the directory of the jars instead of individual jars? and the 2nd question is how can I do that the libraries will be deployed properly when compiling my application ?!
首先,如何添加罐子的目录而不是单个罐子?第二个问题是如何在编译我的应用程序时正确部署库?!
采纳答案by VonC
It can be about:
它可以是关于:
- a simple refreshissue:
- 一个简单的刷新问题:
Can you switch to the navigator view, right-click refresh the project, make sure it's not in the
LIB
dir,
Then try and drag and drop the JAR into thelib
dir and see if it shows up.
你可以切换到导航器视图,右键单击刷新项目,确保它不在
LIB
目录中,
然后尝试将 JAR 拖放到lib
目录中,看看它是否显示出来。
- a process issue (from this cached blog entry, the original onebeing unavailable):
When you have total control of you web container/app server, deploying jar files is as easy as dropping the folder in your common lib folder.
If you don't package your web apps as awar
file then it's even easier because you only have to drop the jars in theWEB-INF/lib
folder of your webapp.
But if you don't have total control of your web server or application server, your only choice is to package the jars you've used with your war file.While developing a web project using my recently developed utility(a jar file), I encountered a
NoClassDefFound
error. Of course, it's pretty obvious that the jar file I've made and using on my web project could not be found (not visible in theCLASSPATH
).
Adding the jar to the build path only eliminated the compilation problem. Dragging the jar file into the lib folder of my Eclipse workspace isn't a very good idea.
It took me a couple of hours before I figured out the solution:
- Right Click on your web project
- Click Properties
- Select J2EE Module Dependencies
- Click the Web Libraries Tab
- Add external jars (if the jar is outside of your project). An entry will be added under
Jar/Module
, make sure you click on the checkbox (checked).And everything should be fine. I tried exporting to a war file and then checked the content and my jar files are indeed deployed with the war.
当您完全控制 Web 容器/应用程序服务器时,部署 jar 文件就像将文件夹放入公共 lib 文件夹中一样简单。
如果您不将 Web 应用程序打包为war
文件,那么它就更容易了,因为您只需要将 jar 放在Web 应用程序的文件WEB-INF/lib
夹中。
但是,如果您不能完全控制您的 Web 服务器或应用程序服务器,您唯一的选择就是将您使用的 jar 与您的 war 文件打包。在使用我最近开发的实用程序(一个 jar 文件)开发一个 web 项目时,我遇到了一个
NoClassDefFound
错误。当然,很明显无法找到我制作并在我的 web 项目中使用的 jar 文件(在CLASSPATH
.
将 jar 添加到构建路径只会消除编译问题。将 jar 文件拖到我的 Eclipse 工作区的 lib 文件夹中并不是一个好主意。
我花了几个小时才找到解决方案:
- 右键单击您的 Web 项目
- 单击属性
- 选择 J2EE 模块依赖项
- 单击 Web 库选项卡
- 添加外部 jar(如果 jar 在您的项目之外)。将在 下添加一个条目
Jar/Module
,请确保单击复选框(已选中)。一切都应该没问题。我尝试导出到一个War文件,然后检查内容,我的 jar 文件确实与War一起部署。
- a project configuration issue
- 一个项目配置问题
The OP ufkmentions in the comment:
OP ufk在评论中提到:
I resolved the issue by:
- adding a "Web App Libraries" library in "java build path"and
- adding all the relevant jars into
WebContent/WEB-INF/lib
我通过以下方式解决了这个问题:
- 在“Java构建路径”添加“Web应用程序库”库和
- 将所有相关的 jars 添加到
WebContent/WEB-INF/lib
回答by ozma
In eclipse Junu:
在 Eclipse Junu 中:
in a web project, after adding jar to build path, one must add it to
在一个web项目中,将jar添加到构建路径后,必须将其添加到
Deployment Assembly
(in project properties)
(在项目属性中)
when adding that jar to "Deployment Assembly" press the add button and select
将该 jar 添加到“部署程序集”时,按添加按钮并选择
Java Build Path Entry
(and not other workspace or file system option)
(而不是其他工作区或文件系统选项)
回答by REDA
I was facing the same problem, like whenever I export my web app as a war file, the external added jar files didn't get included in app/lib directory, causing exceptions during deployment.
我遇到了同样的问题,就像每当我将我的 web 应用程序导出为一个 war 文件时,外部添加的 jar 文件没有包含在 app/lib 目录中,从而导致部署过程中出现异常。
you Have to switch the navigator view, right-click refresh the project, make sure it's not in the LIB dir (but in the project folder)
您必须切换导航器视图,右键单击刷新项目,确保它不在 LIB 目录中(而是在项目文件夹中)
then try and drag and drop the JAR into the lib dir and see if it shows up.
然后尝试将 JAR 拖放到 lib 目录中,看看它是否出现。