Cannot import javax.ejb.* packages

人走茶凉 提交于 2019-12-18 11:07:36

问题


I am having trouble in building an EJB session bean.

The following packages cannot be found:

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.

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). I am using eclipse(kepler) on a Windows 7 x64 machine


回答1:


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:

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



回答2:


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:

  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.


来源:https://stackoverflow.com/questions/20859379/cannot-import-javax-ejb-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!