简体   繁体   中英

How to import javax.faces library in Eclipse using JDK8?

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

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 eg Mojarra here and include the JAR or add the dependency to your POM.xml if you are using Maven. Hope that helps.

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 .

就我而言... ...我去了项目属性,在搜索引擎中我写了构面... ...我去了窗口的右边,选择了“运行时”选项卡,选择“ wildfly” ...然后应用,应用,关闭和解决。 ..

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.

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