Set up Eclipse to work with Java EE
First note that I'm new to EE and particulary to Eclipse (I'm seriosly working with Eclipse for the second time in my life :) ).
Then I have opened Eclipse project that was created by somebody else. It is using Java EE (some EJB, Persistence API...). Cannot run this project, there are compile errors - I cannot get it to use EE libraries - it look 开发者_运维知识库like this:
No Anotations are known to it and there is no quick fix. Also the project contains Maven dependencies (I have managed to install Maven plugin for Eclipse) and all the classes from dependencies show warnings in the code. Like this:
How do I set up Eclipse to work with this EE project to be able to compile and run it ? Thank you for answers.
EDIT: I'm using Eclipse 2.0.0.2 and I have to use it - its the Rational Team Concept version of Eclipse and version above 2.0.0.2 are not compatible with RTC server.
To the point, you've got to include the Java EE API in the buildpath of the project. The Java EE API is in essence the application server, such as for example Oracle Glassfish as you seem to already have.
In Eclipse, open the Servers view at the right bottom box. If there isn't any, then you need to add it. Rightclick there and choose New. The wizard should speak for itself. If there's no option for Sun or Oracle Glassfish, then you've to install the Eclipse plugin separately. In the newer Eclipse versions, you could do that by clicking Download additional server adapters in the top of the wizard and then choosing the Oracle Glassfish Server Tools one. If in older Eclipse version, then you need to install it manually as per the instructions in its homepage.
Once you have the server integrated in Eclipse (or actually already have one), then you should rightclick the dynamic web project and head to the section Targeted runtimes. Select the integrated server there. Rebuild if necessary.
Couple of suggestions
- make your Java level 5 or above by
Window > Preferences > Java Compiler
set drop-down to anything above or equal to 1.5. - Clean your project by clicking on
Project > clean...
- Right click on the top folder of the project and
Maven > update project configuration
andMaven > update project configuration
To build
Right click on the top folder of the project and run as.. > maven clean
and then 'run as.. > maven install`
Hope this helps
BTW, why not use a newer version like Eclipse 3.6.x or newer?
精彩评论