dbflute-session / tomcat-boot

boot library for web application by Tomcat
Apache License 2.0
3 stars 3 forks source link

Research, for Tomcat10 (jakarta) #190

Open jflute opened 1 year ago

jflute commented 1 year ago

TomcatBootをTomcat10にアップグレードして対応できるか?

branch: tomcat10 pull request: https://github.com/dbflute-session/tomcat-boot/pull/191

jflute commented 1 year ago

Tomcat10にしたら、どれだけコンパイルエラーになるだろうか?

jflute commented 1 year ago

あれ?単純にアップグレードしてもコンパイルエラーにならないぞぅ?

<tomcat.version>10.1.13</tomcat.version>
jflute commented 1 year ago

javax.servletを使ってる箇所はある:

// TomcatBoot
import javax.servlet.ServletException;

javax.servletの依存が入っちゃってるから通ってるだけかな。

<!-- servlet -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>${servlet.version}</version>
    <scope>provided</scope>
</dependency>
jflute commented 1 year ago

jakartaにして、6.0.0にしたらちゃんとコンパイルエラーになった

<!-- servlet -->
<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
    <version>${servlet.version}</version>
    <scope>provided</scope>
</dependency>
jflute commented 1 year ago

ServletExceptionのimportを直すだけでコンパイルは通った。

import jakarta.servlet.ServletException;

意外に内部構造は変わってないのかも。 ただ、動かしてみたい。

そういえばTomcatBootが単独で動く環境って用意してないかも。 (LastaFlute環境だと、LastaFluteで対応しないと動かせない)

jflute commented 1 year ago

なぜか、Eclipse上でTestクラスでtestスコープのライブラリのクラスが補完できない。 これはTomcat9のときから同じだろうか?ちょっと環境問題を解決しないと。

jflute commented 1 year ago

これはtomcat9のときから同じだったようだ。テストクラスが一個もなかったから気付かなかった。

harborの.classpathを持ってきたら補完できるようになった:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
    <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
    <classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources">
        <attributes>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

が入ってないといけないようだ。 昔のEclipseだと、これが入って無くても補完できるようになってたけど、 mainでテストのクラスが参照できないようにするためにそうなったんだと思う。 (それはそれで良いこと)

jflute commented 1 year ago

BootBootを作って...

public class BootBoot extends PlainTestCase {

    public static void main(String[] args) {
        new TomcatBoot(8159, "/boot").asDevelopment(true).bootAwait();
    }
}

動かしてみたら、ClassVersionError。

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/catalina/startup/Tomcat has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)

Java8じゃ動かないか。 java8のworkspaceじゃなくてjava17のworkspaceで開発しないと。

jflute commented 1 year ago

java17環境にて:

...Booting the Tomcat: port=8159 contextPath=/boot
...Registering the shutdown hook for the Tomcat: lastModified=2023/08/31 23:26:29.452
...Finding project webapp from stack trace: webappRelativePath=./src/main/webapp
Exception in thread "main" *Not found the project webapp by derived path: /Users/xxx/xxx/workspace/tomcat-boot/./src/main/webapp
java.lang.IllegalStateException: Not found the webapp directory: ./src/main/webapp

webappがないと怒られた。まあそりゃそうだ。 テスト用のwebappの環境を作ってみようかな。

今日はここまで。

jflute commented 2 months ago

再開、とりあえずMaven pluginたちを整備している。 あと、java21環境を作ったので、課題を整理し直して色々と試してみよう。

https://github.com/dbflute-session/tomcat-boot/issues/261