سؤال

I am working with an example of a simple JSF and I am using NetBeans. With NetBeans, I can't seem to resolve these imports

import javax.inject.Named; 

import javax.enterprise.context.SessionScoped; 

but when I go to Eclipse to check, there seems to be no problem. They are found by the Java class created in Eclipse. I was wondering: what are the things that I need to import or configure with NetBeans so that I won't have this problem of my class not seeing packages?

Also, I just updated everything before posting this question

هل كانت مفيدة؟

المحلول 3

they seem to work now after choosing the glassfish as the server. before, I chose tomcat which i guess don't have the imports that i want to use

نصائح أخرى

In the project view expand Libraries and add 'Java EE 6 API Library' this will add the required packages. The required file is javaee-api-6.0.jar.

Alternativly as maven dependency:

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

Check out that the correct reference library is added in netbeans in your applications build path.

A solution to continue developing with Tomcat are change the imports and annotations to:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="namebean")
@SessionScoped

It's an old question but someone can have the same problem ...

@ManagedBean is intended for use with legacy application servers and standalone servlet runners.

@Named is the best choice with a Java EE 6 compliant application server.

If you are using Maven, then you could use the above mentioned dependency in your pom file. Else you could just download the javaee 6 api jar file (javaee-api-6.0.jar) and add it to your class path. That should get it working. It is readily available online. Here is one of those links:
http://www.java2s.com/Code/JarDownload/javaee-api/javaee-api-6.0.jar.zip

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top