Package does not exist after upgrading to Netbeans 8.0.1 and Glassfish 4.1

I am learning JavaEE CDI and I created a small application with NetBeans 8.0 + Glassfish 4. After upgrading to NetBeans 8.0.1 and Glassfish 4.1, I got a lot of errors reporting that some packages do not exist. For example, I can’t use the following code because I get a message that the javax.enterprise.event package does not exist.

package jlacerda; import javax.inject.Inject; import javax.enterprise.event.Event; public class CMensagem { @Inject private Event<Evento> gerarEvento; public String getMensagem() { return "Hello world!"; } public void gerarEvento() { Evento evento = new Evento(); evento.setMensagem("Objeto criado a partir da classe CMensagem"); gerarEvento.fire(evento); } } 

This situation also occurs with packages:

 import javax.enterprise.inject.Alternative; import javax.decorator.Decorator; import javax.decorator.Delegate; import javax.enterprise.inject.Disposes; import javax.enterprise.inject.Produces; import javax.enterprise.inject.spi.InjectionPoint; 

If I changed the server to Glassfish 4.0, the same code will work as expected, and all packages will be correctly imported.

I searched the NetBeans and Glassfish forums, but I did not find a situation like this.

Thanks in advance for any question that may help me in solving this situation.

+2
java java-ee netbeans cdi glassfish
source share
2 answers

Glassfish 4.1 upgraded its version of CDI to version 1.2 (Glassfish 4.0 used CDI 1.1). Since you will not provide information on how your application is packaged, I will give you all the points to check:

  • Make sure there is no cdi-api.jar file in your war

  • Make sure that in your war there is no weld bound jar

  • Use Api CDI version 1.2 to compile code. Check the spec site to download the file or change the Maven configuration as follows


 <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <version>1.2</version> <scope>provided</scope> </dependency> 

There are no changes in the API from 1.1 to 1.2, but all OSGi settings have changed, so you may encounter a problem with these changes.

+3
source share

With NetBeans 8.0.x, you only need to open the "Project Properties", then go to the "Libraries" section and add the "Java EE Web 6 API Library". I have the same problem when porting from NetBeans from 7.4 to 8.0, but the solution is quite simple and obvious.

+4
source share

All Articles