简体   繁体   English

找不到javax.ejb包(Eclipse)

[英]javax.ejb package not found (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. 我已经从Sun安装了Eclipse for Java EE和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或Eclipse for Java EE开发人员的话,此软件包来自何处!

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 : 我使用GlassFish(这是您在Java EE SDK中获得的,对吗?)作为目标运行时生成了一个测试EJB项目

替代文字

And the project definitely includes javax.ejb classes as dependency: 该项目肯定包括javax.ejb类作为依赖项:

替代文字

javax.ejb package is included in the server with ejb container. 带有ejb容器的服务器中包含javax.ejb软件包。 once you configured your target runtime, the package will be added to your project library when you create ejb project 一旦配置了目标运行时,该包将在创建ejb项目时添加到您的项目库中

Right click on your project. 右键单击您的项目。 Go to properties. 转到属性。 Click targeted runtimes. 单击目标运行时。 Check JBoss runtime. 检查JBoss运行时。 Click Ok. 单击确定。

This jar is in the server library. 该罐子在服务器库中。

I assume you have WTP with Java EE development tools for Eclipse. 我假设您具有使用Eclipse的Java EE开发工具的WTP。 In project properties, select Project Facets, make sure you have added one of J2EE runtimes with EJB support (eg JBoss) and then enable EJB Module facet for your project. 在项目属性中,选择Project Facets,确保添加了一个具有EJB支持的J2EE运行时(例如JBoss),然后为您的项目启用EJB Module facet。 you can also create an EJB project using File / New... / Project / EJB Project wizard, though you will still have to add your EJB runtime, eg download and install JBoss server. 您仍然可以使用File / New ... / Project / EJB Project向导创建EJB项目,尽管您仍然必须添加EJB运行时,例如下载并安装JBoss服务器。

The javax.ejb package is NOT made available with standard Java download. 标准Java下载不提供javax.ejb软件包。 If your project has a dependency on it, you need to explicitly download the relevant jar and place it in your build path. 如果您的项目依赖于它,则需要显式下载相关的jar并将其放在构建路径中。 Some of the answers in this thread suggest that you download an application server ( glassfish or jboss ) specific jar. 该线程中的某些答案建议您下载特定于应用程序服务器( glassfishjboss )的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 . 包含此软件包的标准工件是javaee-api Just place it in your build path and Eclipse will stop complaining. 只要将其放在您的构建路径中,Eclipse就会停止抱怨。 Alternately, if you are using a dependency management tool such as Maven, use the following dependency in POM: 或者,如果您正在使用诸如Maven之类的依赖项管理工具,请在POM中使用以下依赖项:

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

Thanks for the help guys. 谢谢你的帮助。 Yes, it would appear that Glassfish is included with the Java EE SDK (though this wasn't immediately apparent). 是的,看来Java EE SDK中包含了Glassfish(尽管现在还不是很明显)。 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”子文件夹-尽管没有任何警告说这行不通)。

As Pascal mentions, I downloaded and installed Glassfish 3 itself and a Glassfish 'server adapter' (available when adding a new server runtime environment). 如Pascal所述,我下载并安装了Glassfish 3本身和一个Glassfish“服务器适配器”(在添加新的服务器运行时环境时可用)。 Now, when targeting the Glassfish runtime environment, it prompted me to select the glassfish subfolder and hence now it works. 现在,在针对Glassfish运行时环境时,它提示我选择glassfish子文件夹,因此现在可以使用了。

Thanks for the help, this is a steep learning curve... :) 感谢您的帮助,这是一个陡峭的学习曲线... :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM