Do you want to get started with JEE6, including JSF2 and JPA2? Here is how you can setup a first simple project using Maven als buildtool.
A sample project can also be download, by this URL.
First of all we need the pom.xml; in which the dependencies are configured. Note that we use the Jetty plugin for testing purposes. The can be started through the maven command “mvn jetty:run”.
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.gjdb</groupId> <artifactId>jee6-demo</artifactId> <packaging>war</packaging> <version>0.0.3-SNAPSHOT</version> <name>jee6-demo</name> <description>Bookmarking application demonstrating JSF, CDI, JPA and Bean Validation on Tomcat/Jetty servlet containers</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <jetty.version>6.1.22</jetty.version> </properties> <dependencies> <!-- JSF Dependencies, normally 'compile' but not in the openjdk/ jetty combination available --> <dependency> <groupId>javax.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.0.2-b10</version> <scope>compile</scope> </dependency> <!-- CDI Dependencies --> <dependency> <groupId>org.jboss.weld.servlet</groupId> <artifactId>weld-servlet</artifactId> <version>1.0.1-Final</version> <scope>compile</scope> </dependency> <!-- Bean Validation Dependencies --> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.0.0.GA</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.0.0.GA</version> <scope>compile</scope> </dependency> <!-- JPA Persistence Dependencies --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.5.0-Beta-2</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <version>1.0.0.Final</version> <scope>compile</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <type>jar</type> <scope>compile</scope> </dependency> <!-- A test in-memory database --> <dependency> <groupId>hsqldb</groupId> <artifactId>hsqldb</artifactId> <version>1.8.0.1</version> </dependency> </dependencies> <build> <finalName>jee6-demo</finalName> <plugins> <plugin> <artifactId>maven-source-plugin</artifactId> <configuration> <attach>false</attach> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>2.0</version> </plugin> <!-- Facilitates downloading source and javadoc in Eclipse --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <wtpversion>2.0</wtpversion> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> </configuration> </plugin> <!-- Plugin to run and test through maven --> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>${jetty.version}</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <stopPort>9966</stopPort> <stopKey>foo</stopKey> <connectors> <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> <port>8081</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> </configuration> </plugin> <!-- Ensures we are compiling at 1.6 level --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
Secondly we need a beans.xml file, which will be empty if we use annotation based configuration.
<?xml version="1.0" encoding="UTF-8"?> <!-- The contents of this file is permitted to be empty. The schema definition is provided for your convenience. --> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans>