fvarrui / JavaPackager

:package: Gradle/Maven plugin to package Java applications as native Windows, MacOS, or Linux executables and create installers for them.
GNU General Public License v3.0
1.07k stars 133 forks source link

run .exe,console close fast ,no any error #441

Closed karlo0820 closed 2 weeks ago

karlo0820 commented 3 weeks ago

Short description of the issue/suggestion: My project is a Javafx project, when I package the EXE and run it, the console closes very quickly and I can't see any errors, how should I go down to analyze the problem, here is the pom of the project

`<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<groupId>com.digitech</groupId>
<artifactId>oct</artifactId>
<version>1.0-SNAPSHOT</version>
<name>oct</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <javafx.version>17.0.8</javafx.version>
    <kotlin.version>1.7.20</kotlin.version>
    <okhttp.version>4.9.3</okhttp.version>
    <fastjson.version>1.2.70</fastjson.version>
</properties>

<dependencies>

    <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus -->
    <!--        <dependency>-->
    <!--            <groupId>com.baomidou</groupId>-->
    <!--            <artifactId>mybatis-plus</artifactId>-->
    <!--            <version>3.5.6</version>-->
    <!--        </dependency>-->

    <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-extension -->
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-extension</artifactId>
        <version>3.4.3</version>
    </dependency>

    <!-- Mysql驱动包 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.29</version>
    </dependency>

    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>4.0.3</version>
    </dependency>

    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.9.0</version>
    </dependency>

    <!--lombok-->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.20</version>
    </dependency>

    <!-- json处理相关 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.70</version>
    </dependency>
    <!--串口-->
    <dependency>
        <groupId>com.fazecast</groupId>
        <artifactId>jSerialComm</artifactId>
        <version>[2.0.0,3.0.0)</version>
    </dependency>

    <dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-all</artifactId>
        <version>5.3.10</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.8</version>
    </dependency>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>5.7.0</version>
    </dependency>

    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>logging-interceptor</artifactId>
        <version>${okhttp.version}</version>
    </dependency>
    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>${okhttp.version}</version>
    </dependency>

    <dependency>
        <groupId>com.squareup.retrofit2</groupId>
        <artifactId>retrofit</artifactId>
        <version>2.8.1</version>
    </dependency>

    <dependency>
        <groupId>com.squareup.retrofit2</groupId>
        <artifactId>adapter-rxjava2</artifactId>
        <version>2.8.1</version>
    </dependency>

    <dependency>
        <groupId>com.squareup.retrofit2</groupId>
        <artifactId>converter-gson</artifactId>
        <version>2.8.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.9.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.sarxos</groupId>
        <artifactId>webcam-capture</artifactId>
        <version>0.3.11</version>
    </dependency>
    <dependency>
        <groupId>io.reactivex.rxjava2</groupId>
        <artifactId>rxjavafx</artifactId>
        <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.opencv</groupId>
        <artifactId>opencv</artifactId>
        <scope>system</scope>
        <version>341</version>
        <systemPath>${project.basedir}/lib/opencv-341.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.opencv</groupId>
        <artifactId>opencv</artifactId>
        <version>1.0</version>
    </dependency>
    <!--动画-->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.8</version>
    </dependency>

    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>javacv-platform</artifactId>
        <version>1.5.9</version>
        <exclusions>
            <exclusion>
                <groupId>org.bytedeco</groupId>
                <artifactId>opencv-platform</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>easyexcel</artifactId>
        <version>3.3.1</version>
    </dependency>

    <dependency>
        <groupId>com.lowagie</groupId>
        <artifactId>itext</artifactId>
        <version>2.1.7</version>
    </dependency>

    <dependency>
        <groupId>org.dcm4che</groupId>
        <artifactId>dcm4che-core</artifactId>
        <version>5.20.0</version>
    </dependency>
    <dependency>
        <groupId>org.dcm4che</groupId>
        <artifactId>dcm4che-imageio</artifactId>
        <version>5.20.0</version>
    </dependency>

    <!--*************************************************************-->

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-web</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-media</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.controlsfx</groupId>
        <artifactId>controlsfx</artifactId>
        <version>11.1.1</version>
    </dependency>

    <dependency>
        <groupId>io.github.palexdev</groupId>
        <artifactId>materialfx</artifactId>
        <version>11.17.0</version>
    </dependency>

    <!--        <dependency>-->
    <!--            <groupId>com.dlsc.formsfx</groupId>-->
    <!--            <artifactId>formsfx-core</artifactId>-->
    <!--            <version>11.5.0</version>-->
    <!--            <exclusions>-->
    <!--                <exclusion>-->
    <!--                    <groupId>org.openjfx</groupId>-->
    <!--                    <artifactId>*</artifactId>-->
    <!--                </exclusion>-->
    <!--            </exclusions>-->
    <!--        </dependency>-->
    <!--        <dependency>-->
    <!--            <groupId>net.synedra</groupId>-->
    <!--            <artifactId>validatorfx</artifactId>-->
    <!--            <version>0.4.0</version>-->
    <!--            <exclusions>-->
    <!--                <exclusion>-->
    <!--                    <groupId>org.openjfx</groupId>-->
    <!--                    <artifactId>*</artifactId>-->
    <!--                </exclusion>-->
    <!--            </exclusions>-->
    <!--        </dependency>-->

    <!--        <dependency>-->
    <!--            <groupId>org.kordamp.ikonli</groupId>-->
    <!--            <artifactId>ikonli-javafx</artifactId>-->
    <!--            <version>12.3.1</version>-->
    <!--        </dependency>-->
    <!--        <dependency>-->
    <!--            <groupId>org.kordamp.bootstrapfx</groupId>-->
    <!--            <artifactId>bootstrapfx-core</artifactId>-->
    <!--            <version>0.4.0</version>-->
    <!--        </dependency>-->
    <!--        <dependency>-->
    <!--            <groupId>eu.hansolo</groupId>-->
    <!--            <artifactId>tilesfx</artifactId>-->
    <!--            <version>17.1.15</version>-->
    <!--            <exclusions>-->
    <!--                <exclusion>-->
    <!--                    <groupId>org.openjfx</groupId>-->
    <!--                    <artifactId>*</artifactId>-->
    <!--                </exclusion>-->
    <!--            </exclusions>-->
    <!--        </dependency>-->
    <!--        <dependency>-->
    <!--            <groupId>com.github.almasb</groupId>-->
    <!--            <artifactId>fxgl</artifactId>-->
    <!--            <version>17.2</version>-->
    <!--            <exclusions>-->
    <!--                <exclusion>-->
    <!--                    <groupId>org.openjfx</groupId>-->
    <!--                    <artifactId>*</artifactId>-->
    <!--                </exclusion>-->
    <!--            </exclusions>-->
    <!--        </dependency>-->

    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>5.1.0</version>
    </dependency>

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-stdlib-jdk8</artifactId>
                <version>${kotlin.version}</version>
            </dependency>

    <dependency>
        <groupId>com.github.oshi</groupId>
        <artifactId>oshi-core</artifactId>
        <version>6.1.5</version>
    </dependency>

    <dependency>
        <groupId>io.github.g00fy2</groupId>
        <artifactId>versioncompare</artifactId>
        <version>1.5.0</version>
    </dependency>

    <dependency>
        <groupId>org.jfxtras</groupId>
        <artifactId>jmetro</artifactId>
        <version>11.6.15</version>
        <exclusions>
            <exclusion>
                <artifactId>javafx-graphics</artifactId>
                <groupId>org.openjfx</groupId>
            </exclusion>
            <exclusion>
                <artifactId>javafx-base</artifactId>
                <groupId>org.openjfx</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.jetbrains</groupId>
        <artifactId>annotations</artifactId>
        <version>23.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.36</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.11</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.2.11</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlinx</groupId>
        <artifactId>kotlinx-coroutines-core</artifactId>
        <version>1.7.2</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlinx</groupId>
        <artifactId>kotlinx-coroutines-javafx</artifactId>
        <version>1.7.2</version>
    </dependency>

</dependencies>

<build>
    <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.10.1</version>
            <configuration>
                <source>17</source>
                <target>17</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <jvmTarget>17</jvmTarget>
            </configuration>
        </plugin>

        <plugin>
            <groupId>io.github.fvarrui</groupId>
            <artifactId>javapackager</artifactId>
            <version>1.7.5</version>

            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>package</goal>
                    </goals>
                    <configuration>
                        <platform>windows</platform>

                        <!--打包后exe名称-->
                        <name>OCT</name>

                        <version>1.0.0</version>

                        <!-- mandatory -->
                        <mainClass>com.digitech.oct.Launcher</mainClass>
                        <!-- 公司名称-->
                        <organizationName>Organization</organizationName>

                        <!-- optional -->
                        <!-- 是否将jvm一起打包到程序中 -->
                        <bundleJre>true</bundleJre>
                        <!--                            <jrePath>D:\Java\jdk1.8.0_212\jre</jrePath>-->
                        <!--                            <jrePath>D:\Jre</jrePath>-->

                        <!--                            <generateInstaller>true</generateInstaller>-->
                        <!--                            <copyDependencies>true</copyDependencies>-->
                        <customizedJre>false</customizedJre>
                        <vmArgs>
                            <vmArg>--add-modules=javafx.base,javafx.controls,javafx.graphics</vmArg>
                            <vmArg>--add-exports=javafx.base/com.sun.javafx=ALL-UNNAMED</vmArg>
                            <vmArg>--add-exports=javafx.base/com.sun.javafx.runtime=ALL-UNNAMED</vmArg>
                            <vmArg>--add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED</vmArg>
                            <vmArg>--add-exports=javafx.base/com.sun.javafx=ALL-UNNAMED</vmArg>
                            <vmArg>
                                --add-exports=javafx.controls/com.sun.javafx.scene.control.skin.resources=ALL-UNNAMED
                            </vmArg>

                            <vmArg>--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED</vmArg>
                            <vmArg>--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED</vmArg>
                            <vmArg>--add-exports=javafx.graphics/com.sun.javafx.text=ALL-UNNAMED</vmArg>
                            <vmArg>--add-exports=javafx.graphics/com.sun.javafx.scene.text=ALL-UNNAMED</vmArg>
                            <vmArg>--add-exports=javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED</vmArg>
                            <vmArg>
                                --add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls=ALL-UNNAMED
                            </vmArg>
                            <vmArg>--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED
                            </vmArg>
                            <vmArg>--add-opens=javafx.graphics/com.sun.javafx.text=ALL-UNNAMED</vmArg>
                            <vmArg>--add-opens=java.base/java.io=ALL-UNNAMED</vmArg>
                            <vmArg>--add-opens=javafx.graphics/javafx.scene.text=ALL-UNNAMED</vmArg>
                            <vmArg>--add-opens=java.base/java.time=ALL-UNNAMED</vmArg>
                            <vmArg>
                                --add-opens=javafx.controls/javafx.scene.control.skin=org.controlsfx.controls=ALL-UNNAMED
                            </vmArg>
                        </vmArgs>
                        <!-- <additionalModulePaths>${pom.basedir}/libs</additionalModulePaths>-->
                        <!-- 其他插件生成的jar名称,这里指的是 spring-boot-maven-plugin -->
                        <!-- <runnableJar>${project.build.directory}/${project.name}-${project.version}.jar</runnableJar>-->
                        <additionalResources>
                            <additionalResource>app</additionalResource>
                        </additionalResources>
                        <!--                            <linuxConfig>...</linuxConfig>-->
                        <!--                            <macConfig>...</macConfig>-->
                        <winConfig>
                            <!-- general properties -->
                            <!--                               <icoFile>path/to/icon.ico</icoFile>-->
                            <!--                                <generateSetup>true</generateSetup>-->
                            <!--                                <generateMsi>true</generateMsi>-->
                            <!--                                <generateMsm>false</generateMsm>-->
                            <headerType><!--gui|console-->console</headerType>
                            <!--                                <productName>${project.name}</productName>-->
                            <!--                                <internalName>${project.name}</internalName>-->
                            <!--                                <fileDescription>${project.description}</fileDescription>-->
                            <!--                                <wrapJar>false</wrapJar>-->
                        </winConfig>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>

</build>

`

Steps to reproduce the issue/enhancement:

  1. [First Step]
  2. [Second Step]
  3. [Other Steps...]

What is the expected behavior?

What is the current behavior?

Do you have outputs, screenshots, demos or samples which demonstrate the problem or enhancement?

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

Other information (e.g. related issues, suggestions how to fix, links for us to have context)

fvarrui commented 3 weeks ago

Hi @karlo0820! Please, try adding <vmArg>--module-path=libs</vmArg>.

karlo0820 commented 3 weeks ago

Hi @karlo0820! Please, try adding <vmArg>--module-path=libs</vmArg>.

Hi,I tried to add <vmArg>--module-path=libs</vmArg> ,But it didn't work.

fvarrui commented 3 weeks ago

Hi @karlo0820! Have you tried to run your app from CMD? Please, share output if possible.

karlo0820 commented 2 weeks ago

yes,I tried to run app from CMD, this is log : 083D8F98-7EAD-4f01-B81D-C933596874F8

fvarrui commented 2 weeks ago

yes,I tried to run app from CMD, this is log : 083D8F98-7EAD-4f01-B81D-C933596874F8

Please, try running EXE ... if you run JAR from that path, it won't be able to find the dependencies. I've seen that you set winConfig.headerType=console, so EXE must show some output on CMD.

karlo0820 commented 2 weeks ago

yes,I tried to run app from CMD, this is log : 083D8F98-7EAD-4f01-B81D-C933596874F8

Please, try running EXE ... if you run JAR from that path, it won't be able to find the dependencies. I've seen that you set winConfig.headerType=console, so EXE must show some output on CMD.

When I run exe, the console shuts down too fast to catch the abnormal output

fvarrui commented 2 weeks ago

yes,I tried to run app from CMD, this is log : 083D8F98-7EAD-4f01-B81D-C933596874F8

Please, try running EXE ... if you run JAR from that path, it won't be able to find the dependencies. I've seen that you set winConfig.headerType=console, so EXE must show some output on CMD.

When I run exe, the console shuts down too fast to catch the abnormal output

Are you running EXE from terminal? If so, I don't know why is closing your terminal

karlo0820 commented 2 weeks ago

Yes, the console shut down very quickly, without any output information, as if the console flashed 4EDA0380-F28A-4fa0-8BED-09B79269C1DD

fvarrui commented 2 weeks ago

Don't run using start command, just EXE, please

karlo0820 commented 2 weeks ago

Don't run using start command, just EXE, please

Okay, this way we already see the exception message 25601383-3903-4165-8561-30229D19DCF8

karlo0820 commented 2 weeks ago

Don't run using start command, just EXE, please

very thankful