简体   繁体   中英

Netbeans cannot find the CDI package javax.enterprise.context.*

I am creating a simple JSF application with one of my university colleagues, and I am having some trouble when I pull down the application from our repository. When I import the project into NetBeans IDE 8.0.1, the program does not compile correctly on the following CDI based annotation:

@Named
@RequestScoped
public class LoginController implements Serializable {...

It is informing me that it cannot find the following package:

import javax.enterprise.context.*;

Initially I had thought that I did not have the EJB and EAR plugin installed, however I have installed the Java EE bundle which I downloaded from the netbeans website. Are there any other JAR's, which I may be possibly missing, causing this specific error.

On my colleagues local machine everything works as expected without any issues at all, so I am left unclear why this is not happening on my computer.

yeah it seem this netbeans version lacking javax.enterprise package. Here is the solution

1) If you are using maven project, add javax.enterprise(cdi-api.jar) as dependency

2) For other projects, download cdi-api.jar, add this as external jar from project properties, it will enable CDI.

I had this problem too. The glassfish library structure has changed somewhat so instead of using the "Java EE from Glassfish" library we used the "Java EE from API" library and that fixed it.

Both proposed solutions are valid but the simplest one is the second one because you've got already everything needed in NetBeans 8.0 .

Your problem is clearly the consequence of the default Java EE bundle (version 7) present in GlassFish 4.1 . Of course, it is a NetBeans bug. Netbeans should have added the needed library to your project when you chose to work with Java EE 6.

Yes you need to include another library. You are using the part that belongs to Java EE. By default java includes Java SE. So you need to add this library in your project.

Go to

Project Properties -> Libraries -> Add Library -> Java EE Web 7 Api Library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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