开发者

javax.ejb package not found (Eclipse)

开发者 https://www.devze.com 2023-01-20 20:10 出处:网络
I have installed Eclipse for Java EE and the Java EE SDK from Sun, and am attempting to create (my first) Java EE application.

I have installed Eclipse for Java EE and the Java EE SDK from Sun, and am attempting to create (my first) Java EE application.

I've created an EJB project, then added a session bean using Eclipse's own wizards, and the package javax.ejb isn't found!

I've configured the Java EE SDK as the target runtime environment, and a JDK 1.6 as the JRE.

What is going on!? Where doe开发者_如何学Cs this package come from if not from the Java EE SDK or Eclipse for Java EE developers!


The javax.ejb package is NOT made available with standard Java download. If your project has a dependency on it, you need to explicitly download the relevant jar and place it in your build path. Some of the answers in this thread suggest that you download an application server (glassfish or jboss) specific jar. That's not ideal. You should rather use an application server agnostic artifacts to satisfy compile time dependencies. The standard artifact that includes this package is javaee-api. Just place it in your build path and Eclipse will stop complaining. Alternately, if you are using a dependency management tool such as Maven, use the following dependency in POM:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>8.0</version>
    <scope>provided</scope>
</dependency>


I couldn't reproduce your issue. I generated a test EJB Project using GlassFish (that's what you get in the Java EE SDK, right?) as Target runtime:

javax.ejb package not found (Eclipse)

And the project definitely includes javax.ejb classes as dependency:

javax.ejb package not found (Eclipse)


I assume you have WTP with Java EE development tools for Eclipse. In project properties, select Project Facets, make sure you have added one of J2EE runtimes with EJB support (e.g. JBoss) and then enable EJB Module facet for your project. you can also create an EJB project using File / New... / Project / EJB Project wizard, though you will still have to add your EJB runtime, e.g. download and install JBoss server.


javax.ejb package is included in the server with ejb container. once you configured your target runtime, the package will be added to your project library when you create ejb project


Right click on your project. Go to properties. Click targeted runtimes. Check JBoss runtime. Click Ok.

This jar is in the server library.


Thanks for the help guys. Yes, it would appear that Glassfish is included with the Java EE SDK (though this wasn't immediately apparent). I think the issue was that targeting this as the runtime didn't bring through the libraries correctly (possibly you need to select the 'glassfish' subfolder within the installation - though there was no kind of warning that this hadn't worked).

As Pascal mentions, I downloaded and installed Glassfish 3 itself and a Glassfish 'server adapter' (available when adding a new server runtime environment). Now, when targeting the Glassfish runtime environment, it prompted me to select the glassfish subfolder and hence now it works.

Thanks for the help, this is a steep learning curve... :)

0

精彩评论

暂无评论...
验证码 换一张
取 消