Getting started with JEE 6, Glassfish and Maven

by 2/05/2010 04:41:00 PM 0 comments

Getting started with JEE 6, Glassfish and Maven

I'm ramping back up on JEE development, so I'm catching up with the latest stuff in JEE 6. To get started I've created a basic Maven POM file for getting me going. The nice thing about this is that the POM will start the glassfish server to execute the tests and the shut it down when they are completed. It can also start up a glassfish instance on the command line with
mvn embedded-glassfish:run
.

pom.xml

<?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>bms</groupId>
    <artifactId>jee-testing</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>jee-testing Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <scope>provided</scope>
            <version>6.0</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.glassfish</groupId>
                <artifactId>maven-embedded-glassfish-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <goalPrefix>embedded-glassfish</goalPrefix>
                    <app>${basedir}/target/${project.artifactId}</app>
                    <port>8080</port>
                    <contextRoot>${project.artifactId}</contextRoot>
                    <autoDelete>true</autoDelete>
                </configuration>
                <!-- Configure glassfish for executing tests -->
                <executions>
                    <execution>
                        <id>start-glassfish</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>glassfish-deploy</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>glassfish-undeploy</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>undeploy</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-glassfish</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <pluginRepositories>
        <pluginRepository>
            <id>maven2.java.net</id>
            <name>Java.net Repository for Maven 2</name>
            <url>http://download.java.net/maven/glassfish</url>
        </pluginRepository>
    </pluginRepositories>
</project>

hohonuuli

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

0 comments: