Maven Build and Deploy Play! App on Glassfish Server

Play! Framework Setup

Download Play! Framework (i currently use 2.3.*)

Unzip it and add ;C:\path\to\activator to your PATH.

To start Play! admin panel from console: activator ui. Then in browser go: http://localhost:8888

To make new application from template via console: activator new

Using Elcipse as IDE for scala-java projects

In Eclipse go Help->Install new software.. Add new http://download.scala-ide.org/sdk/lithium/e44/scala211/stable/site then wait for downloads and restart the program.

Glassfish standalone server run

Download glassfish server. Unzip and that’s it. To start server: cd \pathto\glassfish4\glassfish\bin (you can add it to PATH variable for easy use) and type in console: asadmin start-domain

In browser:

http://localhost:8080 - for landing

http://localhost:4848 - for admin panel

If Windows: Rename glassfish4/glassfish/bin/asadmin to *.s to prevent Maven error.

In the User.m2 directory you can create settings.xml file with glassfish settings for future use, like this:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>glassfish-context</id>
            <properties>
                <local.glassfish.home>C:\\glassfish4\\glassfish</local.glassfish.home>
                <local.glassfish.user>admin</local.glassfish.user>
                <local.glassfish.domain>domain1</local.glassfish.domain>
                <local.glassfish.passfile>
            ${local.glassfish.home}\\domains\\${local.glassfish.domain}\\config\\domain-passwords
                </local.glassfish.passfile>
            </properties>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>glassfish-context</activeProfile>
    </activeProfiles>
</settings>

Maven build and deploy settings

Next goes simple pom file example (note: check of glassfish plugin to put correct paths there. You can use settings.xml to put some settings as variables):

<?xml version="1.0" encoding="UTF-8"?>

<!--
mvn play build and war packaging with glassfish standalone server app deploy
Copyright 2015 Alex Joz (yakimbee at gmail dot com)
-->

<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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.google.code.play2-maven-plugin.test-projects.play23.java</groupId>
    <artifactId>Users</artifactId>
    <version>1</version>
    <packaging>play2</packaging>

    <name>Play! Framework 2.x Maven Test Projects : Play! 2.3.x : Java : Hello World</name>

    <repositories>
        <repository>
            <id>typesafe</id>
            <name>Typesafe - releases</name>
            <url>https://dl.bintray.com/typesafe/maven-releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>codelds</id>
            <url>https://code.lds.org/nexus/content/groups/main-repo</url>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <play2.version>2.3.9</play2.version>
        <scala.version>2.11.6</scala.version>

        <play2.plugin.version>1.0.0-beta3</play2.plugin.version>
        <sbt-compiler.plugin.version>1.0.0-beta5</sbt-compiler.plugin.version>
        <play2war.version>1.3-beta2</play2war.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>

        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play_2.11</artifactId>
            <version>${play2.version}</version>
        </dependency>

        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play-java_2.11</artifactId>
            <version>${play2.version}</version>
        </dependency>

        <dependency>
            <groupId>com.github.play2war</groupId>
            <artifactId>play2-war-core-servlet25_2.11</artifactId>
            <version>${play2war.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>${basedir}/app</sourceDirectory>
        <testSourceDirectory>${basedir}/test</testSourceDirectory>
        <resources>
            <resource>
                <directory>${basedir}/conf</directory>
            </resource>
            <resource>
                <directory>${basedir}/public</directory>
                <targetPath>public</targetPath>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>com.google.code.play2-maven-plugin</groupId>
                <artifactId>play2-maven-plugin</artifactId>
                <version>${play2.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <mainLang>java</mainLang>
                </configuration>
                <executions>
                    <execution>
                        <id>default-play2-enhance</id>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.google.code.sbt-compiler-maven-plugin</groupId>
                <artifactId>sbt-compiler-maven-plugin</artifactId>
                <version>${sbt-compiler.plugin.version}</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                    <primaryArtifact>false</primaryArtifact>
                    <warSourceDirectory>${basedir}/war</warSourceDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>make-war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


            <plugin>
                <groupId>org.glassfish.maven.plugin</groupId>
                <artifactId>maven-glassfish-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                <glassfishDirectory>C:\\glassfish4\\glassfish</glassfishDirectory>
                    <user>admin</user>
                    <passwordFile>C:\\glassfish4\\glassfish\\domains\\domain1\\config\\domain-passwords</passwordFile>
                    <domain>
                        <name>domain1</name>
                        <httpPort>8080</httpPort>
                        <adminPort>4848</adminPort>
                    </domain>
                    <components>
                        <component>
                            <name>${project.artifactId}</name>
                            <artifact>target/${project.artifactId}-${project.version}.war</artifact>
                        </component>
                    </components>
                    <debug>true</debug>
                    <terse>false</terse>
                    <echo>true</echo>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <id>eclipse</id> <!-- for M2Eclipse only -->

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <skipMain>true</skipMain>
                            <skip>true</skip>
                        </configuration>
                        <executions>
                            <execution>
                                <id>default-compile</id>
                                <goals><goal>compile</goal></goals>
                            </execution>
                            <execution>
                                <id>default-testCompile</id>
                                <goals><goal>testCompile</goal></goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

Now put pom.xml in your app dirrectory and web.xml in .\war\WEB-INF and go console:mvn eclipse:eclipse It generates Eclipse configuration files and now you can import as axisting eclipse project. To build your application and make war file: mvn clean package To deploy on glassfish server: mvn glassfish:deploy

Adding Oracle JDBC Dependency

Any Java library, provided as JAR file installed in your application’s lib/ directory is a simple Play dependency, but in order to build everything through Maven you should add it to pom file. Due to binary licences, the Oracle driver is not present in the maven central repository. So, do mvn install of your ojdbc jar like:

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=path/to/ojdbc6.jar -DgeneratePom=true

And add dependency to pom file:

            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc6</artifactId>
                <version>11.2.0.3</version>
            </dependency>

results matching ""

    No results matching ""