We want to use Maven 2 to build and run our application. Maven will try to download the needed dependencies from a remote repository. So please ensure you are connected to the internet. We set up our project with the following command:

mvn archetype:create -DgroupId=net.sf.jpasecurity -DartifactId=jpasecurity-simple-sample -Dversion=0.4.0

This created a directory called jpasecurity-simple-sample with a file named pom.xml and a subdirectory named src in it. Within the src-directory there is a directory-structure special to Maven. We will place our classes in src/main/java. Maven already created the packages net.sf.jpasecurity for us. Within this package Maven created a simple Hello-World-example called App.java. Maven also created src/test/java, but we don't need this directory nor its subdirectories, so we can savely delete it. We now create subfolders in our src/main/java/net/sf/jpasecurity folder named sample/simple and move the App.java into it. Don't forget to correct the package declaration in the App.java to point to the right package:

package net.sf.jpasecurity.sample.simple;

Our sample shall be compiled and executed with Java 5 and shall be packed into an executable jar file. In order to configure Maven to do so, we have to add the following configuration to the pom.xml before the <dependencies> section:


You can now compile our project by issuing the following Maven command from within the jpasecurity-simple-sample folder:

mvn package

If everything is configured correctly this command should end with something like "BUILD SUCCESSFUL" and you can start our application by changing into the subdirectory target and issueing the following command:

java -jar jpasecurity-simple-sample-0.4.0.jar

If you now see the output "Hello World!" you have successfully set up this sample.