简体   繁体   English

Eclipse Not Find Classes 添加到构建路径(Java 动态 Web 项目)

[英]Eclipse Not Finding Classes added to the build Path (Java Dynamic Web Project)

I am taking over a web project from my school.我正在从我的学校接手一个网络项目。 I am trying to deploy the project in eclipse.我正在尝试在 Eclipse 中部署该项目。 The project uses a group of libraries (Namely javax.mail.* , com.sun.mail.* , org.joda.* and org.apache.* ).该项目使用一组库(即javax.mail.*com.sun.mail.*org.joda.*org.apache.* )。 The project can not compile because it is unable to locate these.该项目无法编译,因为它无法找到这些。 I have them in the src folder and then added the three top level folders/packages to the build path.我将它们放在 src 文件夹中,然后将三个顶级文件夹/包添加到构建路径中。 The import statements work.导入语句有效。 But getting the joda.time.CLASSXYZ does not work (Then I instantiate the class CLASSXYZ).但是获取joda.time.CLASSXYZ不起作用(然后我实例化类 CLASSXYZ)。 (The error is "The type org.joda.time.base.BaseDateTime cannot be resolved. It is indirectly referenced from required .class files" the import was joda.time.* so the class should have been imported) (错误是“无法解析类型 org.joda.time.base.BaseDateTime。它是从所需的 .class 文件间接引用的”,导入是joda.time.*所以应该已经导入了该类)

I've looked at the other threads and most of them just explain how to add folders to the build path.我查看了其他线程,其中大多数只是解释了如何将文件夹添加到构建路径。 I have Apache tomcat set up with eclipse.我用 Eclipse 设置了 Apache tomcat。 It works with other projects that I have deployed.它适用于我部署的其他项目。

This problem has gotten pretty frustrating as its preventing me from starting the project.这个问题已经变得非常令人沮丧,因为它阻止了我开始这个项目。 Any help you be much appreciated.非常感谢您的任何帮助。

Cheers干杯

Unless you use maven you need to download additional libraries:除非你使用 maven,否则你需要下载额外的库:

I suggest to place them in a folder 'lib' and add the jar-files to your build class path.我建议将它们放在文件夹“lib”中,并将 jar 文件添加到您的构建类路径中。 (context menu on your project). (项目的上下文菜单)。

The other threads you mentioned are pointing you in the right direction, and provide a good practice to get in to (especially once you start having more than one project running in your eclipse ide).您提到的其他线程为您指明了正确的方向,并提供了一个很好的实践(尤其是当您开始在 eclipse ide 中运行多个项目时)。

So right click project - Build Path - Configure Build Path... , then in the Libraries tab, click Add External JARs and add in the jar for org.joda from the link in the other answer here.因此,右键单击 project - Build Path - Configure Build Path... ,然后在 Libraries 选项卡中,单击 Add External JARs 并从此处其他答案中的链接添加 org.joda 的 jar。 This way you can have all your external jar libraries in one spot and reuse them across multiple projects.通过这种方式,您可以将所有外部 jar 库放在一个位置,并在多个项目中重用它们。 There's also about a dozen different ways to do the same thing in eclipse, but this is the most direct I think.在 eclipse 中也有十几种不同的方法可以做同样的事情,但这是我认为最直接的。 I'm on version Helios (your's might be slightly different).我使用的是 Helios 版本(您的可能略有不同)。 I try not to use source files of external code libraries unless I want to play around, debugging their code - not a bad thing to do - but I never have the time to spare for that.我尽量不使用外部代码库的源文件,除非我想玩弄,调试他们的代码——这不是一件坏事——但我从来没有空闲时间这样做。

Also I'd double check that the other libraries you mentioned aren't being automatically linked in or included as part of the JRE system library.另外,我会仔细检查您提到的其他库是否没有被自动链接或包含在 JRE 系统库中。 Especially if you are setup in a Dynamic Web Project, it would surprise me if org.apache wasn't already there... but I could easily be wrong there, have been many times before & eclipse was usually involved ;-)特别是如果您在动态 Web 项目中进行设置,如果 org.apache 不存在,我会感到惊讶......但我很容易在那里出错,在通常涉及 eclipse 之前已经多次出现 ;-)

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

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