简体   繁体   中英

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

  1. make your Java level 5 or above by Window > Preferences > Java Compiler set drop-down to anything above or equal to 1.5.
  2. Clean your project by clicking on Project > clean...
  3. Right click on the top folder of the project and Maven > update project configuration and Maven > 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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