找不到 javax.ejb 包(Eclipse)

发布于 2024-09-28 00:02:43 字数 278 浏览 2 评论 0原文

我已经安装了 Eclipse for Java EE 和 Sun 的 Java EE SDK,并尝试创建(我的第一个)Java EE 应用程序。

我创建了一个 EJB 项目,然后使用 Eclipse 自己的向导添加了一个会话 bean,但找不到包 javax.ejb!

我已将 Java EE SDK 配置为目标运行时环境,并将 JDK 1.6 配置为 JRE。

到底是怎么回事!?如果这个包不是来自 Java EE SDK 或面向 Java EE 开发人员的 Eclipse,那么它从哪里来?

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 does this package come from if not from the Java EE SDK or Eclipse for Java EE developers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

笙痞 2024-10-05 00:02:43

我无法重现你的问题。我使用 GlassFish(这就是 Java EE SDK 中得到的,对吧?)作为目标运行时生成了一个测试 EJB 项目

alt text

并且该项目肯定包含 javax.ejb 类作为依赖项:

替代文字

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:

alt text

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

alt text

无可置疑 2024-10-05 00:02:43

javax.ejb 包不提供标准 Java 下载。如果您的项目对其有依赖性,则需要显式下载相关 jar 并将其放置在构建路径中。此线程中的一些答案建议您下载应用程序服务器(glassfishjboss)特定的 jar。这并不理想。您应该使用与应用程序服务器无关的工件来满足编译时依赖性。包含此包的标准工件是 javaee- API。只需将其放入您的构建路径中,Eclipse 就会停止抱怨。或者,如果您使用 Maven 等依赖项管理工具,请在 POM 中使用以下依赖项:

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

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>
老街孤人 2024-10-05 00:02:43

我假设您有 WTP 以及适用于 Eclipse 的 Java EE 开发工具。在项目属性中,选择 Project Facets,确保您已添加具有 EJB 支持的 J2EE 运行时之一(例如 JBoss),然后为您的项目启用 EJB Module Facet。您还可以使用 File / New.../Project / EJB Project 向导创建 EJB 项目,但您仍然需要添加 EJB 运行时,例如下载并安装 JBoss 服务器。

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.

殤城〤 2024-10-05 00:02:43

javax.ejb 包包含在带有 ejb 容器的服务器中。配置目标运行时后,当您创建 ejb 项目时,该包将被添加到您的项目库中

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

酷遇一生 2024-10-05 00:02:43

右键单击您的项目。
转到属性。
单击目标运行时。
检查 JBoss 运行时。
单击“确定”。

该 jar 位于服务器库中。

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

This jar is in the server library.

手心的海 2024-10-05 00:02:43

谢谢你们的帮助。是的,Glassfish 似乎包含在 Java EE SDK 中(尽管这一点不是很明显)。我认为问题在于,由于运行时没有正确地引入库(可能您需要在安装中选择“glassfish”子文件夹 - 尽管没有任何警告表明这不起作用),所以以此为目标。

正如 Pascal 提到的,我下载并安装了 Glassfish 3 本身和 Glassfish“服务器适配器”(在添加新的服务器运行时环境时可用)。现在,当针对 Glassfish 运行时环境时,它提示我选择 glassfish 子文件夹,因此现在它可以工作了。

感谢您的帮助,这是一个陡峭的学习曲线......
:)

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...
:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文