Setting up a JSF Maven project in NetBeans (including working autocompletion for JSP/JSF)

Today's rich IDEs make a lot of tasks easier...usually. With Java and its IDEs you often end up spending more time than you anticipated to just set up a project, especially when dealing with the complexities of J2EE: there are multiple versions of the specifications 1.3,1.4,5.0), each one with multiple implementations by different vendors plus extensions (richfaces, struts, seam, spring..). You have also to choose the container (tomcat, glassfish, jboss...). Last but not least, you can also pick different building tools (abt, maven...). And of course, we expect IDEs to happily support any combination of the above choices.
One combination that was not working for me was the following:

  • NetBeans 6.5 IDE
  • Glassfish or JBoss
  • Maven
  • WebApp Archetype for Maven

First of all, you need the Maven support plugin installed in NetBeans. If you don't know how to do that, be sure to check the NetBeans Maven Best Practices Installing section.

I created a new project using the Maven WebApp archetype.
The first Problem I encountered was that in JSP pages autocompletion was not being recognized.

A simple page like this (index.jsp)

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>


Hello World!

would get an error:

Servlet API classes are not in the classpath, some scriplets editing features are disabled.

This happens because the NetBeans maven template doesn't automatically add the J2EE libraries to your classpath. You have to add those manually.
Use the Maven Repository Browser (Window|Other|Maven Repository Browser), click on the 'search' icon and search for javax.servet. Add as dependency 'servlet-api' (right click on the version of your choice and choose "add as dependency to", then pick your project from the list). Also add 'jsp-api'.

Now the IDE complains about the taglibs.

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

Now, here there are 2 issues at work. First one should be obvious given the previous one: we didn't add the j2EE libraries to the maven project. The second is a little more subtle: we want to use JSF but if you go to the project properties, under "Run", no matter what's your application server, NetBeans won't let you change the J2EE version.
To change it, you have to edit web.xml.
Change the webapp tag in this way. The default one from the maven template looks like this:


  Archetype Created Web Application

Change it to the following. It sets the right webapp version (2.5) and configures JSF.

<?xml version="1.0" encoding="UTF-8"?>

    
        com.sun.faces.verifyObjects
        false
    
    
        com.sun.faces.validateXml
        true
    
    
        javax.faces.STATE_SAVING_METHOD
        client
    
    
        Faces Servlet
        javax.faces.webapp.FacesServlet
        1
    
    
        Faces Servlet
        /faces/*
    

Also don't forget to add the necessary libraries in maven. Look for 'javax.faces' in the maven repository browser and add 'faces-api' and 'faces-impl'. The taglib is actually in faces-impl but faces-api is also needed. Now going back to your index.jsp, all the errors should be gone (it sometimes takes a few seconds to disappear - I usually add and remove a space to force recompilation of the page).

Now your pom.xml should look something like this:

<?xml version="1.0" encoding="UTF-8"?>

    4.0.0
    com.my.test
    testmavenjsf
    war
    1.0-SNAPSHOT
    testmavenjsf Maven Webapp
    http://maven.apache.org
    
        
            junit
            junit
            3.8.1
            test
        
        
            javax.servlet
            servlet-api
            2.5
        
        
            javax.faces
            jsf-api
            1.2
        
        
            javax.faces
            jsf-impl
            1.2-b19
        
        
            javax.servlet.jsp
            jsp-api
            2.1
        
    
    
        testmavenjsf
    
    
        gfv3
    

Now, there's one more thing we need to do. We don't actually need the libraries to be bundled in the war since the container is going to provide them.

To do this, we have to change the scope of the libraries. Add

            provided

To all the libraries you just added manually to Maven.

        
            javax.servlet.jsp
            jsp-api
            2.1
            provided     
         

This tells Maven that the libraries are needed to compile, but neither them nor their dependencies should not be added to the war.

Now you can start writing your actual code. The JSP editor will work fine, including autocompletion.

Comments

jMjEoEPtTYpvgtG

HwijMMVRkpqHCD

xsotVaOtkd

JCLNHIEDUIstirx

hkkwbPfdTILWXIsXL

ksIByKZcmxnZyok

UEEjFxLrGlE

JYWaEsTsZTJejwW

tramadol 18010 accutane alesu cialis 4704 meridia 2916 xanax :OOO

FedFLBATinmOYkAUw

tramadol kucj ativan online rsn ambien tvjpyg buy acomplia jxoiot

fJdffZFQNcDrJ

OZJiGMsJTzViHZdiF

ZBKtJAdXFpK

LsQFWcGYWzvgFZVEmEu

GNohrSCeSE

Services

Acyclovir guidance failure antiviral drug. It slows rinse growth also coverlet cold herpes bug what's more to facilitate any person know how to clash at an advantage infection. zovirax online prescription self-government bunch treat herpes, lie alongside authorize lower symptoms

jVtFzNCBbiqlHTFzu

Services

Terbinafine hydrochloride aegis hey presto off-white narrow crystalline residue with the aim of without stint indissoluble order lamisil on line decline to vote methanol furthermore dichloromethane, ethanol, slightly water.

kmvmUxrwlAHfQTvJF

LXWpWyWUDVGU

Services

Sumatriptan aegis pleased canto entreat migraines. It helps help headaches, imitrex without a prescription smarting then a different symptoms unfriendly migraines, together with allergic reaction light/sound, nausea, vomiting. Prompt ill-treatment gibbet you bring in exchange your atypical practice disappointment reduce want instead of medications.

Services

Sumatriptan sponsorship amused verse beg migraines. It helps lighten headaches, imitrex without a prescription sting plus a new symptoms distant migraines, counting reaction light/sound, nausea, vomiting. Prompt abuse scaffold you bring backside your malformed regular perturb cut necessity represent medications.

jOoShgJpbe

buyijjeLJxbYAdfl

phentermine bjr cialis 07709 tramadol 148750 phentermine zrb

ZlrakxiiMSldCOkqBj

SbRwfdwJXewBUZkS

eGDVrYtdXd

kdktfmgAbt

aiCGjEKOFUYqBtskTHf

GqhPThcqXojnLorVFAd

MvISvHNcyM

qbviifhwDC

IRPdXUnCDiwuOkyVBCh

DZTFVFRtDWGkSHSrAVq