February 18, 2014

Maven, EJB, JSF, Primefaces, JPA



How to build an Eclipse project contains:

EJB 3.1 and JSF 2.2 and Primefaces 4 and JPA 2.1

1. Run the following command to create a maven web project

mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DpackageName={package-name} -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false


2. Update the generated pom file as the following file:

pom.xml


<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.group.id</groupId>
    <artifactId>com.art.id</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>product name</name>
    <url>product url</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
 
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
 
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.5.1</version>
        </dependency>
 
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.28</version>
        </dependency>
 
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.0</version>
        </dependency>
 
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.0</version>
        </dependency>
 
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.0</version>
        </dependency>
 
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>4.0</version>
        </dependency>
 
    </dependencies>
 
    <build>
        <finalName>webapp-warfile</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/java</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <includes>
                                <include>**/*.properties</include>
                                <include>**/*.xml</include>
                                <include>**/*.css</include>
                                <include>**/*.html</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
 
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <wtpversion>2.0</wtpversion>
                    <jeeversion>6.0</jeeversion>
                    <additionalProjectFacets>
                        <jst.jsf>2.2</jst.jsf>
                        <jst.java>1.7</jst.java>
                        <jpt.jpa>2.1</jpt.jpa>
                        <jst.web>3.1</jst.web>
                    </additionalProjectFacets>
                </configuration>
            </plugin>
 
        </plugins>
    </build>
</project>


3. Then run mvn eclipse:eclipse

Done!

No comments: