Skip navigation
2011

Now that JBoss 7 CR1 is out, let's play with it.

Because of standards, it should be straightforward to run a Play application packaged as a war in JBoss AS7.

 

Step 1: Download and Install Play

Grab Play framework here and unzip it in the location of you choice, we'll call that location $PLAY_HOME and make sure $PLAY_HOME is in your path.

 

Step 2: Verify installation

Type:

play

and you should see:

~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.1, http://www.playframework.org
~
~ Usage: play cmd [app_path] [--options]
~ 
~ with,  new      Create a new application
~        run      Run the application in the current shell
~        help     Show play help
~


Step 3: Download and install JBoss AS 7

Get a copy of JBoss AS 7 here. Unzip it and we'll name the home directory of AS7 $JBOSS_HOME.

To verify that the installation went well, go to $JBOSS_HOME/bin and type:

standalone.sh

or

standalone.bat

You will see something like:

=========================================================================


  JBoss Bootstrap Environment


  JBOSS_HOME: /tmp/jboss-7.0.0.CR1


  JAVA: java


  JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman


=========================================================================


11:23:59,956 INFO  [org.jboss.modules] JBoss Modules version 1.0.0.CR4
11:24:00,262 INFO  [org.jboss.msc] JBoss MSC version 1.0.0.CR2
11:24:00,321 INFO  [org.jboss.as] JBoss AS 7.0.0.CR1 "White Rabbit" starting
11:24:01,326 INFO  [org.jboss.as] creating http management service using network interface (management) port (9990) securePort (-1)
11:24:01,336 INFO  [org.jboss.as.logging] Removing bootstrap log handlers
11:24:01,351 INFO  [org.jboss.as.connector.subsystems.datasources] (Controller Boot Thread) Deploying JDBC-compliant driver class org.h2.Driver (version 1.2)
11:24:01,543 INFO  [org.jboss.as.naming] (Controller Boot Thread) Activating Naming Subsystem
11:24:01,562 INFO  [org.jboss.as.naming] (MSC service thread 1-4) Starting Naming Service 
11:24:01,576 INFO  [org.jboss.as.osgi] (Controller Boot Thread) Activating OSGi Subsystem
11:24:01,598 INFO  [org.jboss.as.security] (Controller Boot Thread) Activating Security Subsystem
11:24:01,606 INFO  [org.jboss.remoting] (MSC service thread 1-2) JBoss Remoting version 3.2.0.Beta2
11:24:01,631 INFO  [org.xnio] (MSC service thread 1-2) XNIO Version 3.0.0.Beta3
11:24:01,665 INFO  [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.0.0.Beta3
11:24:01,862 INFO  [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-1) The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
11:24:01,908 INFO  [org.jboss.as.ee] (Controller Boot Thread) Activating EE subsystem
11:24:01,937 INFO  [org.jboss.as.jmx.JMXConnectorService] (MSC service thread 1-3) Starting remote JMX connector
11:24:01,959 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) Listening on /127.0.0.1:9999
11:24:01,990 WARN  [org.jboss.osgi.framework.internal.URLHandlerPlugin] (MSC service thread 1-2) Unable to set the URLStreamHandlerFactory
11:24:02,012 WARN  [org.jboss.osgi.framework.internal.URLHandlerPlugin] (MSC service thread 1-2) Unable to set the ContentHandlerFactory
11:24:02,383 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-1) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
11:24:02,603 INFO  [org.jboss.as.connector] (MSC service thread 1-2) Starting JCA Subsystem (JBoss IronJacamar 1.0.0.CR2)
11:24:02,750 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) Bound data source [java:jboss/datasources/ExampleDS]
11:24:03,318 INFO  [org.jboss.as.deployment] (MSC service thread 1-1) Started FileSystemDeploymentService for directory /tmp/jboss-7.0.0.CR1/standalone/deployments
11:24:03,345 INFO  [org.jboss.as] (Controller Boot Thread) JBoss AS 7.0.0.CR1 "White Rabbit" started in 3742ms - Started 91 of 146 services (55 services are passive or on-demand)

Now point your web browser to localhost:8080 and you should see:

as7.png

Step 4: Package a Play application as a Web Archive (WAR)

We will take the "booking" application that comes with play and is a replicate of the famous booking sample application for Seam.

Warning: For 'some' reason, the #{welcome /} inclusion of Play doesn't work in the servlet environment, so if you try to create a new application from scratch, don't be surpised to not see all the content.

 

In $PLAY_HOME/samples-and-tests/ type:

play war booking -o /tmp/jboss-7.0.0.CR1/standalone/deployments/booking.war

You should see in JBoss AS log (if  you still have it running):

11:30:04,645 INFO  [org.jboss.as.deployment] (DeploymentScanner-threads - 1) Found booking.war in deployment directory. To trigger deployment create a file called booking.war.dodeploy

We'll just do what it says and create an empty file next to booking.war called booking.war.dodeploy. This file is just a marker to tell the application server that all files have been copied and it's ready to be deployed since we haven't zipped the war.

So create that empty file (with a text editor or simply using touch if you are on a linux/Mac machine)

touch $JBOSS_HOME/standalone/deployments/booking.war.dodeploy

And you should see in JBoss AS log:

12:03:18,020 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) Starting deployment of "booking.war"
12:03:19,976 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
12:03:19,985 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
12:03:19,985 WARN  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) Unable to instantiate driver class "com.mysql.jdbc.Driver": org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.booking_war is already registered
12:03:20,149 INFO  [stdout] (MSC service thread 1-2) 12:03:20,148 INFO  ~ Starting /tmp/jboss-7.0.0.CR1/standalone/deployments/booking.war/WEB-INF/application
12:03:20,217 INFO  [stdout] (MSC service thread 1-2) 12:03:20,217 INFO  ~ Application is precompiled
12:03:20,889 INFO  [stdout] (MSC service thread 1-2) 12:03:20,889 INFO  ~ Connected to jdbc:h2:mem:play;MODE=MYSQL
12:03:21,328 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-2) Hibernate Validator 4.1.0.Final
12:03:21,335 INFO  [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] (MSC service thread 1-2) Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
12:03:21,427 INFO  [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] (MSC service thread 1-2) Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
12:03:21,436 INFO  [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] (MSC service thread 1-2) Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
12:03:21,722 INFO  [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] (MSC service thread 1-2) Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
12:03:22,205 INFO  [stdout] (MSC service thread 1-2) 12:03:22,205 INFO  ~ Application 'Hotel Booking' is now started !
12:03:22,963 INFO  [stdout] (MSC service thread 1-2) 12:03:22,963 WARN  ~ Precompiled template /conf/data.yml not found, trying to load it dynamically...
12:03:23,750 INFO  [stdout] (MSC service thread 1-2) 12:03:23,750 INFO  ~ Forcing PROD mode because deploying as a war file.
12:03:23,760 INFO  [org.jboss.web] (MSC service thread 1-2) registering web context: /booking
12:03:23,767 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "booking.war"

Now point your browser to http://localhost:8080/booking and you will see:

booking.png

And that's it, the application is now running in the best application server in the world , you can go ahead and use the services provided by a Java EE container, including application management.

 

This was my first experience with Play Framework on AS7 a better experience would be to remove the Servlet layer and hit JBoss Netty directly to get the best of both worlds. Any volunteer to work on that ?

 

See this in action on this video (Bare with me, first video and upload issues with the processed version on Vimeo, so it is very rough)

 

Enjoy !

Filter Blog

By date:
By tag: