Search code examples
javaprimefacesprojectlibrariesnew-operator

new java primefaces project libraries is empty


I have a little problem when creating a new java ee project with primefaces.

when I get to the frameworks page the libraries are empty.

I do not understand why.

I give you two pictures to show you.

do you have a solution?

thank you in advance

for example :

snapshot1

snapshot2


Solution

  • From your screenshots, it looks like you are using a recent version of NetBeans, and a project that you created using:

    File > New Project > Java with Ant > Java Web > Web Application

    (The following notes assume a Tomcat web container. If you are using something different, some of the points below may also be different - but the main points should be the same.)

    My preference would be to use a Maven-based project rather than an Ant-based one:

    File > New Project > Java with Maven > Web Application

    With Maven

    You will not need to specify any frameworks when creating the project. To start using PrimeFaces, edit the pom.xml file which was automatically generated as part of your project - it is in the Project Files folder.

    In the POM you will see the following section - and you will see I have added a new dependency sub-section for PrimeFaces:

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>8.0</version>
        </dependency>
    </dependencies>
    

    The javaee-web-api dependency which was automatically created in the POM takes care of the JSF requirement (needed by Primefaces).

    Finally, run a Build (F11), to ensure the newly added dependency is pulled into your project. You will see the primefaces-8.0.jar listed in the project's Dependencies folder.

    Now you can create a test XHTML web page to verify that PrimeFaces is working:

    enter image description here

    With Ant

    If you still prefer or need to use an Ant-based approach, then the process is similar. At step 4, choose the registered library for "JSF 2.3" (the one shown in your screenshot) and click on "Finish", instead of trying to select the PrimeFaces component library.

    Now, because you are not using Maven, you will have to manually download the PrimeFaces JAR file (e.g. from the jar link on this page), and maually add it to your project, in the usual way for Ant-based projects:

    Project properties > Libraries > Add JAR/Folder

    (This is one reason why I prefer Maven - the library downloads are automated for you.)

    Updates - based on comments

    Ant-based Dependency Management

    If you need/want to use an Ant-based project, it is worth the effort to set up Maven-like support for dependency management. There is more than one way to do this. Using Ivy is one option.

    Tomcat vs. App Servers

    In my answer, my starting assumption was to use Tomcat. Tomcat is an example of a web container, which provides support for Java servlets - but it is not a fully-fledged Jakarta EE application server - and as such it does not contain the required JSF libraries (hence they needed to be provided as noted in the steps described earlier in this answer). If you are using an app server such as Glassfish, or TomEE (or many others), then JSF will be provided already.

    JSF Version

    For a web container such as Tomcat, NetBeans may not have the version of JSF you want/need to use. In this case, as a separate step, you can download the required JAR files (e.g from Maven or from the official JSF web site).

    In NetBeans, go to Tools > Libraries > New Library... Then give your library a name and provide the required JAR file(s).

    This library will now be available in the "new project" wizard:

    enter image description here

    Just to reiterate, however, you do not need to use the NetBeans wizard to select the JSF widget framework you want to use (e.g. PrimeFaces). It is easier to simply provide that as a JAR/library dependency in your project, in the usual way.