Blank.war, only with logging, spring, JSF, Jetty and Acegi.
Here is a nice little blank.war all ready for your creative juices to draw a pretty picture on. As an added little something, it has Spring, Log4J, JSF 2, Jetty and basic Acegi security thrown in the mix. Plus, it’s all managed by good ol’ Maven. Yes people, this is your lucky day.
Download the project files here.
Here is what I did to create the war using the latest Java, Eclipse with M2Eclipse and Maven.
- Create the project
- Fire up eclipse. Create a new Maven project (Skip archetype selection, enter groupId and artifact Id and click finish).
- Set the dependencies
Add the dependencies for JSF, Servlets, log4J, spring framework and acegi.
com.sun.faces
jsf-api
2.0.3-SNAPSHOT
com.sun.faces
jsf-impl
2.0.3-SNAPSHOT
javax.servlet
servlet-api
2.5
compile
javax.servlet
jstl
1.2
log4j
log4j
1.2.16
org.springframework
spring
2.5.6
acegisecurity
acegi-security
1.0.0
compile
- Add the plugins
Add jetty-maven-plugin and maven-compiler-plugin - Tweak the plugins
We added the maven-compiler plugin because we wanted to change the default location of generated class files. You see, the jetty plugin uses various source directory while running so we can quickly turn it on or off, and edit pages as we run them without having to package a war every time. Jetty is able to pick up the right classes, however the Faces annotation provider only seems to look in WEB-INF\classes folder, which ofcourse doesn’t exist until a war is actually packaged inside the target folder. So, we put our classes where the annotation provider is looking for them. That is, in the WEB -INF\classes folder of the source directory. This is against the Maven convention, but this gets the boat rowed without harming anyone. So, we put this line in the compiler plugin:
src/main/webapp/WEB-INF/classes
(See Tomasz Lipinski’s post at https://bugs.eclipse.org/bugs/show_bug.cgi?id=288243) - Add log4J (in the resources directory).
- Add web.xml, telling spring to look for all files with name like *-spring-config.xml in the classpath. This helps us separate our short spring-beans configuration, and the onerous acegi configuration files.
- Even though we use annotations to define our managed beans, we still need faces-config file to define the delegationg variable resolver to make our spring beans accessible to our faces managed beans. I use Spring for my services and faces for my managed beans in the view.
- See the acegi tutorial for acegi configuration.