无法导入 javax.ejb.* 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20859379/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:50:52  来源:igfitidea点击:

Cannot import javax.ejb.* packages

javaeclipsejakarta-eeejb

提问by Sebi

I am having trouble in building an EJBsession bean.

我在构建EJB会话 bean时遇到了问题。

The following packagescannot be found:

packages无法找到以下内容:

import javax.ejb.LocalBean;
import javax.ejb.Stateful;
import javax.ejb.TransactionManagement; 
import javax.ejb.TransactionManagementType;

Some solutions implied adding the libraries j2ee.jarand javaee.jar to the java build path.

一些解决方案暗示将库j2ee.jarjavaee.jar添加到 java 构建路径。

I am using jdk-7u75-windows-x64and java_ee_sdk-7-windows-mland cannot find any of these libraries at the given location($JAVA_HOME\lib). I am using eclipse(kepler) on a Windows 7 x64machine

我正在使用jdk-7u75-windows-x64并且java_ee_sdk-7-windows-ml在给定位置($JAVA_HOME\lib)找不到任何这些库。我在Windows 7 x64机器上使用 eclipse(kepler)

采纳答案by Sebi

javaee.jar ships with neither eclipse nor java(jdk). The file must be manually downloaded and added to the project build path. The java ee 7 api can be found here.Alternatively, a maven dependency can be used:

javaee.jar 既没有 eclipse 也没有 java(jdk)。该文件必须手动下载并添加到项目构建路径中。可以在此处找到 java ee 7 api 或者,可以使用 Maven 依赖项:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
</dependency>

回答by Yserbius

The EJB API is found in the JavaEE libraries which are, as you correctly pointed out, distributed with the j2ee.jar library. If you're using Eclipse, its classpath may be pointing to the standard Java libraries and not the Enterprise libraries. You can try two things:

EJB API 位于 JavaEE 库中,正如您正确指出的那样,它与 j2ee.jar 库一起分发。如果您使用 Eclipse,它的类路径可能指向标准 Java 库而不是企业库。您可以尝试两件事:

  1. Compile and run your code from the command line. Set %JAVA_HOME% to point to the installation directory of java_ee_sdk-7-windows-ml and add %JAVA_HOME%/bin to the %PATH%.
  2. Find the Enterprise library and add it to your CLASSPATH in Eclipse. The CLASSPATH is set by going to the project properties and selecting the option "Add an external library/jar file". Add any jar files found in the EE installation directory to the build path.
  1. 从命令行编译并运行您的代码。设置%JAVA_HOME%指向java_ee_sdk-7-windows-ml的安装目录,在%PATH%中添加%JAVA_HOME%/bin。
  2. 找到 Enterprise 库并将其添加到 Eclipse 中的 CLASSPATH。通过转到项目属性并选择“添加外部库/jar 文件”选项来设置 CLASSPATH。将在 EE 安装目录中找到的任何 jar 文件添加到构建路径。