thad eirich


Using Maven to package and then deploy Ember-CLI assets as a WAR

Created at: 2014-10-17 14:21:44 UTC

Updated on: 2014-10-17 14:38:33 UTC

Recently I was asked to develop an EmberJS application for a client and one of the requirements was that the application needs to be deployed, much to my dismay, on WebLogic. I tried explaining to the client that they were better off deploying the Ember’s static assets on a separate Apache webserver, or even filtering the requests under Embers base route to an Apache on the same server. However, this was for a Java shop and I was told the application had to follow their standard deploy process.

And so I began!


First I created a WEB-INF in the root of my Ember-CLI directory with an empty web.xml & a simple weblogic.xml with a context root for the ember application.
Web.xml

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
</web-app>

Weblogic.xml

<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic-web-jar.dtd">
<weblogic-web-app>
<context-root>/emberApp</context-root>
</weblogic-web-app>

Next I created a pom.xml so I could manage the build process with Maven. I added no dependencies and the only plugin you need is the maven-assembly-plugin which allows you to filter out files by extension in your build path & package them as a WAR (or zip or whatever).
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gov.research.nsf</groupId>
<artifactId>ip-landing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ip-landing</name>
<build>
<finalName>ip-landing</finalName>
<plugins>

<plugin>
<!-- assamble static content -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>static.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

The maven-assembly-plugin pulls it’s configuration from a file called static.xml which I’ve copied below. In this case I have it configured to pull anything out of my dist folder (automatically generated by Ember CLI) and anything out of the WEB-INF folder I just created.
<assembly>
<id>static</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>dist</directory>
<includes>
<include>**/*</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>WEB-INF</directory>
<includes>
<include>**/*</include>
</includes>
<outputDirectory>/WEB-INF</outputDirectory>
</fileSet>
</fileSets>
</assembly>

Now that everything’s in place, the WAR build process is as follows. `ember build`, `mvn package` & WAR file should now be located in your project root, /target/EmberApp.WAR. The WAR can just be deployed as a normal web application in weblogic.

Note! If you begin encountering problems requesting your other Ember assets, it’s probably because you didn’t establish your baseURL in config/environment.js. In this case you would change the value of baseURL to ‘/emberApp/’. Also, at the time of CLI 0.1.0 I get compatibility problems in IE if I don’t also set the router rootRUL to the same value. So your app/router.js should look something like:

var Router = Ember.Router.extend({
location: YourEmberNamespaceENV.locationType,
rootURL: YourEmberNamespaceENV.baseURL
});

maven ember emberjs ember-cli cli package deploy weblogic WAR java