LoginSignup
7
3

More than 5 years have passed since last update.

Struts2をJDK11環境で動かすために必要なこと

Posted at

Struts2はjdk7以降で動作するのだが…

一部の公式プラグインで上位のバージョン(8~11)で動かないこともあるため、Struts2プラグインから利用している他ライブラリもあわせてバージョンをあげると動作します。

jdkのバージョン8や10の対応でStruts2.5の中核部がセキュリティフィックスも含めてリファクタリング&利用ライブラリのバージョン修正もされていますので、動作確認バージョンの再確認は適宜必要です。

なお、本件の対応は、Struts2.5.17 のみを対象としています。Struts2.3系は別途対応が必要です。

対応内容

mavenへの対応

maven-compiler-plugin

jdk11への対応が必要です。今までsourceやtarget要素でバージョンを指定していましたが、これを解除して release を使います。

pom.xml(build抜粋)
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <release>11</release>
                </configuration>
            </plugin>
   .........

Struts2-Plugin

Struts2-Springプラグイン

Struts2内部ではSpring4.2系を使っており、DIコンテナとして利用しています。5.0/5.1にあげても特に問題なく動作します。

Struts2-Conventionプラグイン, Struts2-Restプラグイン

ASM のバージョンを6系にします。2018年9月の段階では、最新安定板の 6.2.1 で動作確認済みです。

pom.xml(dependencies抜粋)
    <dependencies>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-convention-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
...
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>6.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm-commons</artifactId>
            <version>6.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm-tree</artifactId>
            <version>6.2.1</version>
        </dependency>

Struts2-JSONプラグイン

デフォルトでは特に変更は不要ですが、もしJSONレスポンスの出力設定クラスを org.apache.struts2.json.JSONWriter から変更した場合は、jdk11でも動作するかを確認しましょう。特に古いバージョンのJacksonやJSonicを使っている場合は依存ライブラリの影響で動かない可能性があります。

Struts2-Thymeleaf3プラグイン

Conventionプラグインと同じ対応で問題ありません。バージョン1.2.0のみ動作します。

7
3
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
7
3