4

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:

alt text

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:

alt text

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.

Rasto
  • 17,204
  • 47
  • 154
  • 245
  • This is what I've done until now: I have installed Java EE 6 to directory `C:\glassfishv3`. I have set default JDK in Eclipse (`Window->Preferences->Java->Installed JREs->Add->Next->JRE home` to `C:\glassfishv3\jdk` and removed other JREs from 'Installed JREs'). – Rasto Jan 23 '11 at 17:49
  • Possible duplicate of [How do I import the javax.servlet API in my Eclipse project?](http://stackoverflow.com/questions/4076601/how-do-i-import-the-javax-servlet-api-in-my-eclipse-project) – Paul Wasilewski May 17 '16 at 11:08

2 Answers2

5

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

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?

Nishant
  • 54,584
  • 13
  • 112
  • 127
  • I have done all you have suggested and it downloaded some liberies and then I got: `[ERROR] Failed to execute goal on project Dodavatel: Could not resolve dependencies for project 1.0:Dodavatel:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: toplink.essentials:toplink-essentials:jar:2.0-36, javax.persistence:persistence-api:jar:1.0b: Could not transfer artifact toplink.essentials:toplink-essentials:jar:2.0-36 from/to toplink (http://download.java.net/maven/1): No connector available to access repository toplink (http://download.java.net/maven/1) of ` – Rasto Jan 23 '11 at 18:13
  • `type legacy using the available factories AsyncRepositoryConnectorFactory, WagonRepositoryConnectorFactory -> [Help 1]` – Rasto Jan 23 '11 at 18:14