背景
Efwにかかるjarがだんだん多くなるので、コンパイル便利のため、Mavenプロジェクト方式を利用してみました。やり方をメモします。
プロジェクト作成
自分のは、Eclipse2023を利用しています。Mavenが内蔵しているから、昔のバージョンより簡単にプロジェクトを作れます。
メニューから新規⇒Mavenプロジェクトを選択します。
また、Eclipseが用意された各テンプレートの使い方をよく知らないので、「シンプルなプロジェクト」をチェックします。
成果物エリアのグループid、アーティファクトId、バージョンとパッケージングを登録します。完了ボタンを押すとプロジェクトのひな型が作成されます。
JDK1.8、main/java、main/resources、test/java、test/resourcesの四つのフォルダが作れています。
この四つのパスの定義は、.classpathに定義されています。つまり手動で調整してもよいでしょう。
また、pom.xmlファイルに対して右クリックのポップアップメニューには「実行」メニューが6つのサブメニューがあります。
clean (一時ファイルの削除)
generate-sources (ソースコードの自動生成)
POMファイル設定
POMファイルにはプロジェクトの基本情報、依存関係、ビルド設定などがあります。以下のEfw5の完成版POMファイルには、1~36行は基本情報です。37~147行は依存関係です。148~最後はビルド設定です。
https://github.com/efwGrp/efw5.X/blob/main/sources/project4javax/pom.xml
プロパティ設定
ソースの文字コードとJDKのバージョンを設定します。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<configuration-source>21</configuration-source>
<configuration-target>21</configuration-target>
</properties>
プロパティ設定の詳細は、以下のリンクでご参考ください。
https://maven.apache.org/pom.html#Properties
また、JDK21を利用するため、プロジェクトのプロパティのjavaのビルド・パスも設定する必要です。
依存関係の設定
tomcat関連の依存関係
tomcatのservletとjspなど、Webに関わる要素は、以下のように設定します。
※7、8、9と10、11はgroupIdが違うので要注意です。
<!-- Tomcat7,8,9 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
scopeがprovidedの意味は、これらのjarはコンテナーから提供するとの意味です。scopeがほかの設定値もありますが、Efw5のコンパイルにはあまり複雑な設定がありません。scopeの詳細内容は、添付資料をご参考ください。
GraalJsエンジンの依存関係
GraalJsは、Efw5にとって必須です。つまり、scopeはcompileのデフォルトであるから設定が不要です。
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>polyglot</artifactId>
<version>24.2.2</version>
</dependency>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>js</artifactId>
<version>24.2.2</version>
<type>pom</type>
</dependency>
type=pomの設定がありますが、その意味はこの依存関係設定が一つのjarに対するものではなく、詳細は別のpomをご参考することです。typeに関する詳細は以下のリンクをご参考ください。
https://maven.apache.org/ref/3.9.11/maven-core/artifact-handlers.html
Efwオプション機能の依存関係
ほかのjarはコンバイン時必要ですが、実行する場合関連機能が利用される場合それらのjarが必要です。例えば以下のメール関連の設定です。
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
<optional>true</optional>
</dependency>
optional=trueを利用しています。関連する機能が利用される場合、該当jarが必要です。
Buildの設定
Build設定に、プラグイン機能を利用して、javadocとsourcesを作成するように設定しています。install実行時、efw-5.00.000-javadoc.jarとefw-5.00.000-sources.jarが作成されます。また、署名ファイルを作成して、Mavenにアップするためのzipファイルを作成します。
javadoc作成
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.11.2</version>
<configuration>
<quiet>true</quiet>
<outputDirectory>doc</outputDirectory>
<show>public</show>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
sources作成
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
zip作成
powershellを利用してzipを作成します。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<id>run-powershell-script</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>powershell.exe</executable>
<arguments>
<argument>-ExecutionPolicy</argument>
<argument>Bypass</argument>
<argument>-File</argument>
<argument>${project.basedir}/createZip.ps1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
createZip.ps1
$prj = "efw5x"
$ver = "5.00.000"
cd .\target
copy-item ../pom.xml efw-$ver.pom
gpg -ab efw-$ver.pom
gpg -ab efw-$ver-javadoc.jar
gpg -ab efw-$ver.jar
gpg -ab efw-$ver-sources.jar
(Get-FileHash -Algorithm MD5 efw-$ver.pom).Hash | Out-File -FilePath efw-$ver.pom.md5 -Encoding Ascii
(Get-FileHash -Algorithm MD5 efw-$ver-javadoc.jar).Hash | Out-File -FilePath efw-$ver-javadoc.jar.md5 -Encoding Ascii
(Get-FileHash -Algorithm MD5 efw-$ver.jar).Hash | Out-File -FilePath efw-$ver.jar.md5 -Encoding Ascii
(Get-FileHash -Algorithm MD5 efw-$ver-sources.jar).Hash | Out-File -FilePath efw-$ver-sources.jar.md5 -Encoding Ascii
(Get-FileHash -Algorithm SHA1 efw-$ver.pom).Hash | Out-File -FilePath efw-$ver.pom.sha1 -Encoding Ascii
(Get-FileHash -Algorithm SHA1 efw-$ver-javadoc.jar).Hash | Out-File -FilePath efw-$ver-javadoc.jar.sha1 -Encoding Ascii
(Get-FileHash -Algorithm SHA1 efw-$ver.jar).Hash | Out-File -FilePath efw-$ver.jar.sha1 -Encoding Ascii
(Get-FileHash -Algorithm SHA1 efw-$ver-sources.jar).Hash | Out-File -FilePath efw-$ver-sources.jar.sha1 -Encoding Ascii
md io\github\efwgrp\efw\$ver
move-item efw-$ver*.* io\github\efwgrp\efw\$ver\
Compress-Archive io io.zip
remove-item io -Force -Recurse