Search code examples
javamavenjarexelaunch4j

launch4j-generated exe starts slowly at first time


We are using launch4j-maven-plugin to generate an exe, used is Java 1.8. The jar is generated with onejar because it contains jars as dependencies. However the jar is starting immediately, only the exe needs 30s - 1m to start at first. If I close the application after loaded completely and restart, then the application starts immediately. Maybe, because the dependencies of the jar are already loaded?!

I tried to generate with the maven-shade-plugin (only to check) and the same problem with the start occurs. Moreover I tried to start the application in a debugger and it also starts immediately. Starting the exe with --l4j-debug-all doesn't show anything.

Is there a possibility to speed-up?

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
            </plugin>

            <plugin>
                <groupId>com.jolira</groupId>
                <artifactId>onejar-maven-plugin</artifactId>
                <version>1.4.4</version>
                <executions>
                    <execution>
                        <configuration>
                            <mainClass>${mainclass}</mainClass>
                            <attachToBuild>true</attachToBuild>
                            <filename>${project.artifactId}-${project.version}-jar-with-dependencies.${project.packaging}</filename>
                        </configuration>
                        <goals>
                            <goal>one-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>1.7.25</version>
                <executions>
                    <execution>
                        <id>l4j-clui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <jar>${project.build.directory}/${project.artifactId}-${project.version}-jar-with-dependencies.${project.packaging}</jar>
                            <outfile>${project.build.directory}/App-${project.version}.exe</outfile>
                            <classPath>
                                <mainClass>com.simontuffs.onejar.Boot</mainClass>
                                <preCp>anything</preCp>
                            </classPath>
                            <jre>
                                <minVersion>1.8.0</minVersion>
                                <initialHeapSize>1024</initialHeapSize>
                                <maxHeapSize>1024</maxHeapSize>
                            </jre>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

Solution

  • In my case, a simple reason: the Live-Antivirus-Scan in the background slowed it down.