5

Based on the advice to use JSF, the following sample would like to be run in order to learn more about JSF and to implement this technique into the servlet. However, a number of libraries is unable to be imported:

package tobedefinedservlet;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Hello {

    final String world = "Hello World!";

    public String getworld() {
        return world;
    }
}

javax.faces

The import javax.faces cannot be resolved

ManagedBean

ManagedBean cannot be resolved to a type

Community
  • 1
  • 1
030
  • 10,842
  • 12
  • 78
  • 123

4 Answers4

3

You have to include a JSF library like for example Mojarra in the classpath of your application.

First of all have a look at the Primefaces user guide (especially chapter 2.2). You can download e.g. Mojarra here and include the JAR or add the dependency to your POM.xml if you are using Maven. Hope that helps.

Anton Sorokin
  • 494
  • 6
  • 23
LarsBauer
  • 1,539
  • 18
  • 23
  • First of all have a look at the [Primefaces user guide](http://www.primefaces.org/documentation) (especially chapter 2.2). You can download e.g. Mojarra [here](https://javaserverfaces.java.net/nonav/2.2/download.html) and include the JAR or add the dependency to your `POM.xml` if you are using Maven. Hope that helps. It is not quite clear what is your problem. – LarsBauer May 18 '16 at 17:01
1

If you're using maven for build automation, add the latest jsf-api dependency to your pom.xml:

<dependency>
    <groupId>javax.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1</version>
</dependency>

Or the latest javax.faces-api implementation:

<dependency>
  <groupId>javax.faces</groupId>
  <artifactId>javax.faces-api</artifactId>
  <version>2.3</version>
</dependency>

However, note that JSF is integrated into most Java EE application servers, such as JBoss.

See also this answer.

Woodchuck
  • 3,869
  • 2
  • 39
  • 70
1

in my case ...I went to project properties and in the search engine I wrote facets ... I went to the right of the window and selected the runtime tab and select wildfly ... then apply and apply and close and solve ...

0

If you're not using maven you have to manually install the jar. You can download it at this link:

javax.faces

If you're using eclipse you can right click your Web App project and click properties at the bottom. Then under the java build path make sure the libraries panel at the top is selected then select the Web App library and on the right click Add External JARS. You can go to your downloads folder and select the jsf-api-2.1.jar and refresh the project and you can now import that annotation.

Woodchuck
  • 3,869
  • 2
  • 39
  • 70
Michael
  • 201
  • 2
  • 9