微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – eclipse helios:tomcat project – jar不会被导出或发布.运行时可能会导致ClassNotFoundExceptions

我正在使用 Eclipse Helios,我想知道如何将库项目添加到我的文件夹中,该文件夹将被复制到我编译的项目所在的构建目录中.

目前我做了以下事情:

>在我的项目的根目录中创建了一个lib目录
>将相关的罐子复制到那个目录
>我的项目 – >属性 – > Java构建路径 – >添加罐子,我添加了该目录中的所有罐子.

添加所有jar后,我得到了关于每个jar文件的以下警告:

jar will not be exported or published. runtime ClassNotFoundExceptions may result

首先,我如何添加罐子的目录而不是单个罐子?
第二个问题是如何在编译应用程序时正确部署库?

解决方法

它可以是:

> a simple refresh期:

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 the lib dir and see if it shows up.

>流程问题(从cached blog entry开始,original one不可用):

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 a war file then it’s even easier because you only have to drop the jars in the WEB-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 the CLAsspATH).
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:

  1. Right Click on your web project
  2. Click Properties
  3. Select J2EE Module Dependencies
  4. Click the Web Libraries Tab
  5. 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.

>项目配置问题

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

原文地址:https://www.jb51.cc/java/127480.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐