Java MavenでJava FXプロジェクトを新規作成し,Hello Worldをするまで

black laptop computer turned on showing computer codes
目次

MavenでJFXプロジェクトの生成

% mvn archetype:generate \
        -DarchetypeGroupId=org.openjfx \
        -DarchetypeArtifactId=javafx-archetype-simple \
        -DarchetypeVersion=0.0.3 \
        -DgroupId=org.openjfx \
        -DartifactId=sample \
        -Dversion=1.0.0 \
        -Djavafx-version=19

インタラクティブモードでプロパティを聞かれますの入力します.

[INFO] Using property: javafx-version = 19
[INFO] Using property: javafx-maven-plugin-version = 0.0.3
[INFO] Using property: groupId = org.openjfx
[INFO] Using property: artifactId = sample
[INFO] Using property: version = 1.0.0
[INFO] Using property: package = org.openjfx

生成前にプロパティの確認をされます.問題なければyで進めます.

Confirm properties configuration:
javafx-version: 19
javafx-maven-plugin-version: 0.0.3
groupId: org.openjfx
artifactId: sample
version: 1.0.0
package: org.openjfx

以下のようにINFOが出力されてプロジェクトの生成が完了します.

[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: javafx-archetype-simple:0.0.3
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.openjfx
[INFO] Parameter: artifactId, Value: sample
[INFO] Parameter: version, Value: 1.0.0
[INFO] Parameter: package, Value: org.openjfx
[INFO] Parameter: packageInPathFormat, Value: org/openjfx
[INFO] Parameter: package, Value: org.openjfx
[INFO] Parameter: groupId, Value: org.openjfx
[INFO] Parameter: javafx-version, Value: 19
[INFO] Parameter: artifactId, Value: sample
[INFO] Parameter: version, Value: 1.0.0
[INFO] Parameter: javafx-maven-plugin-version, Value: 0.0.3
[INFO] Project created from Archetype in dir: /Users/[user]/Development/maven-jfx-sample/sample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  17.972 s
[INFO] Finished at: 2022-12-30T13:47:51+09:00
[INFO] ------------------------------------------------------------------------

フォルダ構造を確認します.

% tree sample
sample
├── pom.xml
└── src
    └── main
        └── java
            ├── module-info.java
            └── org
                └── openjfx
                    ├── App.java
                    └── SystemInfo.java

JavaFXプログラムのpom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.openjfx</groupId>
    <artifactId>sample</artifactId>
    <version>1.0.0</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>19</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>org.openjfx.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

JavaFXプログラムの実行

cd sample
mvn clean javafx:run

JavaFXの画面が表示されます.

ブログランキングに参加しています。記事が役に立ったら是非クリックで応援お願いします。

  ブログランキング・にほんブログ村へ
よかったらシェアしてね!
目次