Thursday, 13th October 2011
Follow WikiJava on twitter now. @Wikijava

Starting a Spring 3.0 Hibernate project with AppFuse

From WikiJava

Jump to: navigation, search


In this article I'll guide you through using Maven with AppFuse to generate a fully working J2EE web project that uses Spring, Hibernate, Spring security and lot of other tools, all ready to be used in a top standards base project.

As an additional step I'll show you how to import this project in eclipse, and version it using GIT.

Contents

How it works

AppFuse can be very easily used as a Maven plugin. It offers several archetypes that generates many kinds of different template projects.

The one we'll be using here is the: appfuse-basic-spring-archetype.

Which generates a J2EE project, preconfigured with spring 3.0, hibernate, spring security, DWR (direct web remoting for simplifying ajax calls), ehcache and a lot more.

You can get all this very simply using a single prompt command, using Maven.

The Maven command to start up the project can be automatically created at app fuse website. What you'll get will look like this:

mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes \ 
-DarchetypeArtifactId=appfuse-basic-spring-archetype \
-DarchetypeVersion=2.1.1-SNAPSHOT \
-DgroupId=org.wikijava \ 
-DartifactId=AppFuseExample \
-DarchetypeRepository=http://oss.sonatype.org/content/repositories/appfuse

All you need to do is to change to the directory of your eclipse workspace and copy paste the command generated above. This will create a subdirectory called like whatever you wrote in the "artifactId" parameter above (in this example "AppFuseExample").

This new directory is a J2EE project ready to be deployed and with very basic functionalities, which you can extend in few steps. (I'll show you in the next article "expanding on the appfuse project" how to implement on this base)

To be able to run this you need to have mysql server installed on your machine. Which is very easy and you can do following the instructions on Mysql website.

Once you have mysql installed and running as a server, you can run your new application, to see that it all works.

Change to the project directory and type:

mvn jetty:run

This will use Maven to install jetty app server on your project directory, deploy your project in the jetty, and start the jetty server on the port 8080. So you can now see your new application just browsing to http://localhost:8080/

If all goes well you will see in your browser the page below. (you can login as user:user or admin:admin)

image:AppfuseFirstScreenshot.jpg

importing your AppFuse Project in Eclipse

Eclipse is a great tool, and you definitely want to work on your project using this IDE. This can be done very easily again using Maven. It's just one prompt command away, and it is already well described in the article Using Maven and Eclipse, the basics. Using Appfuse and this procedure I had a little problem, so instead of the maven command in the article I used the following:

mvn org.apache.maven.plugins:maven-eclipse-plugin:2.6:eclipse \
-DdownloadSources=true \
-DdownloadJavadocs=true

which uses the (older) version 2.6 of the plugin which solves the problem.

versioning everything with GIT

At this point all is left to do is to add versioning to your project, so you can track changes and play around without risk.

To do this follow the articke I've written Revisioning your project using GIT


Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page


Comments on wikijava are disabled now, cause excessive spam.