Thursday, June 23, 2016

WildFly Swarm JSF example

WildFly Swarm now has a generator. Thus generating a pom.xml for JSF application bundled into one jar file has become super easy. See example below

<?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>test</groupId>
 <artifactId>test</artifactId>
 <name>WildFly Swarm JSF Test</name>
 <version>1.0.0-SNAPSHOT</version>
 <packaging>war</packaging>

 <properties>
  <version.wildfly.swarm>1.0.0.CR1</version.wildfly.swarm>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
  <failOnMissingWebXml>false</failOnMissingWebXml>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 </properties>

 <dependencyManagement>
  <dependencies>
   <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>bom</artifactId>
    <version>${version.wildfly.swarm}</version>
    <scope>import</scope>
    <type>pom</type>
   </dependency>
  </dependencies>
 </dependencyManagement>

 <build>
  <finalName>test</finalName>
  <plugins>
   <plugin>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>wildfly-swarm-plugin</artifactId>
    <version>${version.wildfly.swarm}</version>
    <executions>
     <execution>
      <goals>
       <goal>package</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>

 <dependencies>
  <dependency>
   <groupId>org.omnifaces</groupId>
   <artifactId>omnifaces</artifactId>
   <version>2.3</version>
  </dependency>
  <!-- Java EE 7 dependency -->
  <dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-api</artifactId>
   <version>7.0</version>
   <scope>provided</scope>
  </dependency>
  <!-- Wildfly Swarm Fractions -->
  <dependency>
   <groupId>org.wildfly.swarm</groupId>
   <artifactId>bean-validation</artifactId>
  </dependency>
  <dependency>
   <groupId>org.wildfly.swarm</groupId>
   <artifactId>cdi</artifactId>
  </dependency>
  <dependency>
   <groupId>org.wildfly.swarm</groupId>
   <artifactId>jsf</artifactId>
  </dependency>
 </dependencies>
</project>
Run mvn package && java -jar target/test-swarm.jar. The result

The whole jar is 117M and starts in a few seconds, no runtime penalty observed. Not very convenient for development due to long compile and start time but very convenient for distribution.
Full source code is available.