未找到 javax.ejb 包(Eclipse)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3979044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javax.ejb package not found (Eclipse)
提问by Dave
I have installed Eclipse for Java EE and the Java EE SDK from Sun, and am attempting to create (my first) Java EE application.
我已经安装了用于 Java EE 的 Eclipse 和来自 Sun 的 Java EE SDK,并且正在尝试创建(我的第一个)Java EE 应用程序。
I've created an EJB project, then added a session bean using Eclipse's own wizards, and the package javax.ejb isn't found!
我创建了一个 EJB 项目,然后使用 Eclipse 自己的向导添加了一个会话 bean,但没有找到包 javax.ejb!
I've configured the Java EE SDK as the target runtime environment, and a JDK 1.6 as the JRE.
我已将 Java EE SDK 配置为目标运行时环境,并将 JDK 1.6 配置为 JRE。
What is going on!? Where does this package come from if not from the Java EE SDK or Eclipse for Java EE developers!
到底是怎么回事!?如果不是来自 Java EE SDK 或 Java EE 开发人员的 Eclipse,那么这个包从哪里来!
回答by Pascal Thivent
I couldn't reproduce your issue. I generated a test EJB Projectusing GlassFish (that's what you get in the Java EE SDK, right?) as Target runtime:
我无法重现您的问题。我使用 GlassFish(这就是您在 Java EE SDK 中得到的,对吧?)作为目标运行时生成了一个测试EJB 项目:
And the project definitely includes javax.ejb
classes as dependency:
并且该项目肯定包含javax.ejb
类作为依赖项:
回答by Eugene Kuleshov
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.
我假设您拥有用于 Eclipse 的 Java EE 开发工具的 WTP。在项目属性中,选择 Project Facets,确保您已添加支持 EJB 的 J2EE 运行时之一(例如 JBoss),然后为您的项目启用 EJB Module facet。您还可以使用 File / New... / Project / EJB Project 向导创建 EJB 项目,但您仍然需要添加 EJB 运行时,例如下载并安装 JBoss 服务器。
回答by tanghao
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
javax.ejb 包包含在带有 ejb 容器的服务器中。一旦您配置了目标运行时,当您创建 ejb 项目时,该包将被添加到您的项目库中
回答by Karthik Sam
Right click on your project. Go to properties. Click targeted runtimes. Check JBoss runtime. Click Ok.
右键单击您的项目。去属性。单击目标运行时。检查 JBoss 运行时。单击确定。
This jar is in the server library.
这个 jar 在服务器库中。
回答by VHS
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:
javax.ejb
标准 Java 下载不提供该软件包。如果您的项目依赖它,则需要明确下载相关的 jar 并将其放置在您的构建路径中。该线程中的一些答案建议您下载特定于应用程序服务器(glassfish
或jboss
)的 jar。这并不理想。您应该使用与应用程序服务器无关的工件来满足编译时依赖性。包含此包的标准工件是javaee-api。只需将它放在您的构建路径中,Eclipse 就会停止抱怨。或者,如果您使用的是 Maven 等依赖项管理工具,请在 POM 中使用以下依赖项:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
回答by Dave
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).
谢谢你们的帮助。是的,Glassfish 似乎包含在 Java EE SDK 中(尽管这不是很明显)。我认为问题在于运行时没有正确通过库(可能您需要在安装中选择“glassfish”子文件夹 - 尽管没有任何警告表明这不起作用)。
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.
正如 Pascal 所提到的,我下载并安装了 Glassfish 3 本身和一个 Glassfish“服务器适配器”(在添加新的服务器运行时环境时可用)。现在,当针对 Glassfish 运行时环境时,它提示我选择 glassfish 子文件夹,因此现在它可以工作了。
Thanks for the help, this is a steep learning curve... :)
感谢您的帮助,这是一个陡峭的学习曲线... :)