LoginSignup
0
0

More than 5 years have passed since last update.

WildFly Swarm上でJSFを動かす。

Posted at

やりたいこと

簡単に動かせるWebシステムを作成したい。

何故、WildFly Swarmか

作成したシステムをDockerイメージに埋め込みたい。
docker build中にApp Serverのインストール+git経由でアプリケーションデプロイの二つを入れるととても時間がかかるので、Javaのインストールだけで済むWildFly Swarmにした。

環境・バージョン

WildFly-Swarm :2017.4.0
開発環境 : Eclipse Version Neon.3 Release (4.6.3)
Java : version "1.8.0_131"

手順

参考URLにあるサンプルコードをもとに作成しています。というかほぼそのままです。

pom.xmlの作成

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         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>GID</groupId>
  <artifactId>AID</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <name>NAME</name>
  <packaging>war</packaging>

  <properties>
    <version.wildfly.swarm>2017.4.0</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>
    <version.postgresql>9.4.1208</version.postgresql>
  </properties>

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

  <build>
    <finalName>FILENAME</finalName>
    <plugins>
      <plugin>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>wildfly-swarm-plugin</artifactId>
        <version>${version.wildfly.swarm}</version>
        <configuration>
          <fractions>
            <fraction>jsf</fraction>
          </fractions>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>package</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <version>1.2</version>
    </dependency>
  </dependencies>
</project>

web.xmlの作成

参考URLのものをそのまま使用しました。

index.xhtmlの作成

index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Title</title>
</h:head>

<h:body>

    JSF on Swarm.<br/>
    <h:outputText value="#{app.test()}"/><br/>

</h:body>
</html>

App.javaの作成

App.java
package package;

import javax.enterprise.inject.Model;

@Model
public class App {
    public String test() {
        return "This messege is from JSF.";
    }
}

参考URL

JSF .war Example

あれこれ

できあがるJarは100M程度。
各種ライブラリで色んなものが便利になるのは良いのですが、その分デプロイ時に結構時間がかかるようになってます。
アプリをいじることが少ないデモ用で大量にアプリが必要!なんて時に良いかなって思いました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0