0

I have done a Maven project and I would like to export it into a runnable exe (or jar file).

After I exported it into runnable .jar file, the file wouldn't open.

What I did -> Right click on project -> Refresh -> Export -> Runnable Jar File -> Package Required ...

Same thing for .exe file, I used launch4j and exported to an .exe file and it wouldn't run either.

What I did -> Right click on project -> Refresh -> Export -> Runnable Jar File -> Extract Required ... JRE min: 1.11.0 (I'm using openjdk-11.0.2)

Does anybody have any tips on this? Thank you!

Updated:

<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>com.flexus</groupId>
    <artifactId>FMOTracker</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <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>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics </artifactId>
            <version>11</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.15</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </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.4</version>
                <configuration>
                    <mainClass>com.flexus.FMOTracker.App</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>fully.qualified.MainClass</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <!-- LAUNCH4J -->
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>l4j-clui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <jar>target/FMOTracker-0.0.1-SNAPSHOT-jar-with-dependencies.jar</jar>
                            <outfile>target/FMOTracker.exe</outfile>
                            <downloadUrl>https://java.com/en/download/manual.jsp</downloadUrl>
                            <classPath>
                                <mainClass>com.flexus.FMOTracker.App</mainClass>
                            </classPath>
                            <jre>
                                <runtimeBits>64</runtimeBits>
                                <minVersion>1.11.0</minVersion>
                                <jdkPreference>preferJre</jdkPreference>
                            </jre>
                            <versionInfo>
                                <fileVersion>1.0.0.0</fileVersion>
                                <txtFileVersion>${project.version}</txtFileVersion>
                                <fileDescription>${project.name}</fileDescription>
                                <copyright>C</copyright>
                                <productVersion>1.0.0.0</productVersion>
                                <txtProductVersion>1.0.0.0</txtProductVersion>
                                <productName>${project.name}</productName>
                                <internalName>AppName</internalName>
                                <originalFilename>AppGUI.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.flexus.FMOTracker.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- LAUNCH4J ENDE -->
        </plugins>
    </build>
</project>

What I did:

clean compile assembly:single -> Jar file with dependencies created

clean package -> exe file created

Problem: The exe file opens and closes immediately. How do I fix this? Is this because of my source code error?

Updated pt.2:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/flexus/FMOTracker/App 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)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Update Pt3: I have changed minJre to 1.11.0 Error: JavaFX runtime components are missing, and are required to run this application

Although, I have openjdk 11.0.2 installed.

openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

I also have javafx sdk 11.0.2 external jres file in my user library

My VM arguments

--module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml```
Kevin
  • 31
  • 1
  • 9

1 Answers1

1

Right click on project -> Run As -> Maven build It will ask the Goals : clean package

You will find the jar in target

If Maven build is intended for something else, use Run configurations and create a new Run with the goals above

(all this, taken as granted it is a maven project, otherwise, you might want to mavenize it before, including the launch4j configuration in order to generate the exe file)

inquirymind
  • 135
  • 1
  • 11
  • Hey Inquirymind, I have tried your way and found my exe jar file in target folder, but it still does not run – Kevin Jan 14 '20 at 21:15
  • What does it say when you try to run? The size is similar to the one generated by eclipse? – inquirymind Jan 14 '20 at 21:33
  • It does not say or pop-up anything at all. The size is significantly less than the one generated by Eclipse – Kevin Jan 14 '20 at 21:51
  • You might share the pom with us, so we can try to guess what's going on – inquirymind Jan 14 '20 at 21:53
  • No reference to launch4j in the pom. Here an example https://stackoverflow.com/questions/37295726/create-exe-with-launch4j-with-maven – inquirymind Jan 14 '20 at 22:01
  • Hi, I will try it and let you know soon! Thanks – Kevin Jan 14 '20 at 22:03
  • Hi I have updated the post, please take a look. Thanks! – Kevin Jan 15 '20 at 15:53
  • 1
    Are you executing on command line? Please share the output with us – inquirymind Jan 15 '20 at 20:59
  • I have updated the error. It looks like the compiler is outdated .. – Kevin Jan 16 '20 at 21:10
  • You are running with Java8 after having compiled with java 11. Try changing the minor version of jre in launch4j configuration 1.8 -> 1.11 – inquirymind Jan 17 '20 at 19:29
  • I changed and got a new error ```Error: JavaFX runtime components are missing, and are required to run this application```. I have openjdk 11.0.2 installed – Kevin Jan 20 '20 at 17:23
  • Have to tried this? https://stackoverflow.com/a/52603536/12493323 – inquirymind Jan 20 '20 at 18:48
  • Hey, the problem is if I try to compile with goal clean compile javafx:run. It will work perfectly. I have installed jre as javafx jdk 11.0.2 with added external jres (javafx.etc). Again, once I run it with goal clean package, it will generate .exe file but open and close immediately. Run in cmd and the error javafx run time .. above still there. – Kevin Jan 20 '20 at 19:08
  • It evolved into a problem beyond maven and exe generation. It is about Java 11 modules. You might want to create a new post specialized (java-11 and java-modules tags) – inquirymind Jan 21 '20 at 10:35