14

I am reading the book Getting Started with WebSphere Application Server Community Edition.

I created an EJB project with Eclipse EE.

import javax.ejb.Local;

Error: The import javax.ejb cannot be resolved

I don't know why I cannot import this class.

Thanks

Eric Francis
  • 23,039
  • 31
  • 88
  • 122
  • 1
    I found the answer. I have WAS 7.0 installed - I can add the j2ee jar to my classpath or I have Glashfish3 installed which has javaee.jar; I can add that to my classpath as well – Eric Francis Mar 22 '12 at 21:09
  • 1
    Specifically, WAS_HOME/dev/JavaEE/j2ee.jar is intended for compilation. – Brett Kail Mar 23 '12 at 05:10
  • What's the difference in that jar and the one in WAS_HOME/lib/ ? – Eric Francis Mar 23 '12 at 12:17
  • WAS_HOME/lib/ is product internals. IBM might decide to remove or rename the JAR in a future release. It might work for your local installation, but it's not a good idea for compilation scripts (batch, ant, etc.). It's a best practice to use WAS_HOME/dev/. – Brett Kail Mar 23 '12 at 15:50
  • If you r deploying the bean in GlassFish Server, then you will get those jar files in %GLASSFISH_HOME%/modules/javax.ejb.jar which will solve the problem type resolution. – Babanna Duggani May 14 '12 at 07:07
  • If using JBoss7, then add jboss-ejb-api_3.1_spec.1.0.1.Final.jar as an External jar in Eclipse. – Shashi May 29 '14 at 10:30

2 Answers2

25

Probably the comments under the question already answered this, but just in case clarification is needed:

1) In Eclipse, right click on the project --> properties --> java build path

2) Click on add external JAR

3) Add c:\glassfish4\glassfish\lib\javaee.jar (Your directory path to this JAR can of course be different.)

--> Ok the dialog, and now Eclipse should be able to see javax.ejb.* classes.

Daniel
  • 1,352
  • 1
  • 14
  • 16
5

Please note that this jar file is useful in development, but you need not (should not?) deploy it along with your war or ear files, because the application server container has its own runtime Java EE environment.

Peter
  • 131
  • 1
  • 4