0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

assemblyでの提供方法

Posted at

Javaアプリケーションの配布方式

  • Webアプリケーション以外の配布方式をよく悩む
  • jar-with-dependenciesがいいのか、それともtar.gzなのか
  • 設定ファイルを修正したくなるので、tar.gzがいいのかと思ったりもする。
    • でも、配布後に設定ファイル修正されてしまうってのも考えものなので、修正していいファイルとそうでないファイルは分けたいような気もする。
  • いったん今日は固め方のみ

ベースとなるプロジェクト

  • v5-sample
  • バッチのサンプルプロジェクト
  • jarで固めて実行するだけなのだけれど、packageしたものをNexusなどに登録しておく前提で考えてみた。

maven-assembly-pluginで固めて配布

  • 以下のように定義してみる。
(pom.xml)
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptor>src/main/assembly/bin.xml</descriptor>
        <finalName>${artifactId}-${pom.version}</finalName>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
        <goals>
            <goal>single</goal>
        </goals>
        </execution>
    </executions>
</plugin>
  • assemblyの定義
(bin.xml)
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
  <id>bin</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>src/main/script</directory>
      <outputDirectory>bin</outputDirectory>
      <includes>
        <include>*.sh</include>
      </includes>
    </fileSet>
    <!-- <fileSet> これ書くと、src/main/resourcesがconfに出力
      <directory>src/main/resources</directory>
      <outputDirectory>conf</outputDirectory>
    </fileSet> -->
    <fileSet>
      <directory>target</directory>
      <outputDirectory></outputDirectory>
      <includes>
        <include>*.jar</include>
      </includes>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <unpack>false</unpack>
      <scope>runtime</scope>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>
  </dependencySets>
</assembly>
(start.sh)
# !/bin/bash

SCRIPT_DIR=$(cd $(dirname $0);pwd)
PARENT_DIR=$(cd $(dirname $0);cd ..;pwd)


AP_CLASSPATH="${PARENT_DIR}/*:${PARENT_DIR}/lib/*"
MAIN_CLASS="org.springframework.batch.core.launch.support.CommandLineJobRunner"

java -cp "${AP_CLASSPATH}" ${MAIN_CLASS} META-INF/jobs/job01.xml job01
  • 要は、
    • 自分で書いた部分をjarにまとめて、dependencyのjarをlibディレクトリに集める。
    • 起動スクリプトをsrc/main/scriptに書いておいて、packageでbin/start.shに移動。
    • で、全部をtar.gzで固めて配布(Nexusなどにdeploy)

成果物

  • tar.gzの中身は以下のようになる。
drwxr-xr-x   6 xxxx  staff    192  1 26 00:48 .
drwxr-xr-x  11 xxxx  staff    352  1 26 00:33 ..
drwxr-xr-x   3 xxxx  staff     96  1 26 00:33 bin
drwxr-xr-x  37 xxxx  staff   1184  1 26 00:33 lib
-rw-r--r--   1 xxxx  staff  12616  1 26 00:20 projectName-5.1.0.RELEASE.jar
  • あとは、confどうするか。もっと綺麗な形を悩んでみよう
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?