简体   繁体   English

无法导入javax.ejb。*包

[英]Cannot import javax.ejb.* packages

I am having trouble in building an EJB session bean. 我在构建EJB会话bean时遇到了麻烦。

The following packages cannot 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.jar and javaee .jar to the java build path. 一些解决方案暗示将库j2ee.jarjavaee .jar添加到java构建路径中。

I am using jdk-7u75-windows-x64 and java_ee_sdk-7-windows-ml and cannot find any of these libraries at the given location($JAVA_HOME\\lib). 我正在使用jdk-7u75-windows-x64jdk-7u75-windows-x64 java_ee_sdk-7-windows-ml并且在给定位置找不到任何这些库($ JAVA_HOME \\ lib)。 I am using eclipse(kepler) on a Windows 7 x64 machine 我在Windows 7 x64机器上使用eclipse(kepler)

javaee.jar ships with neither eclipse nor java(jdk). javaee.jar既没有eclipse也没有java(jdk)。 The file must be manually downloaded and added to the project build path. 必须手动下载该文件并将其添加到项目构建路径中。 The java ee 7 api can be found here. java ee 7 api可以在这里找到 Alternatively, a maven dependency can be used: 或者,可以使用maven依赖项:

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

The EJB API is found in the JavaEE libraries which are, as you correctly pointed out, distributed with the j2ee.jar library. EJB API位于JavaEE库中,正如您正确指出的那样,它与j2ee.jar库一起分发。 If you're using Eclipse, its classpath may be pointing to the standard Java libraries and not the Enterprise libraries. 如果您正在使用Eclipse,则其类路径可能指向标准Java库而不是Enterprise库。 You can try two things: 你可以尝试两件事:

  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%. 将%JAVA_HOME%设置为指向java_ee_sdk-7-windows-ml的安装目录,并将%JAVA_HOME%/ bin添加到%PATH%。
  2. Find the Enterprise library and add it to your CLASSPATH in Eclipse. 找到Enterprise库并将其添加到Eclipse中的CLASSPATH。 The CLASSPATH is set by going to the project properties and selecting the option "Add an external library/jar file". 通过转到项目属性并选择“添加外部库/ jar文件”选项来设置CLASSPATH。 Add any jar files found in the EE installation directory to the build path. 将EE安装目录中找到的任何jar文件添加到构建路径。

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

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