graalvm / native-build-tools

Native-image plugins for various build tools
https://graalvm.github.io/native-build-tools/
Other
349 stars 51 forks source link

Created Exe of Spring boot application Using GraalVM, It will immediately terminate after start #552

Open abhijeeta94 opened 6 months ago

abhijeeta94 commented 6 months ago

Please refer below pom.xml file which I am using <?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<!-- parent> <groupId>com.kpit.diagnostics.build</groupId> <artifactId>kpit-parent-pom</artifactId> 
    <version>1.11.0</version> </parent -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.0</version>
</parent>
<groupId>com.kpit.diagnostics.tf2</groupId>
<artifactId>tf2-product-launcher-application</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>tf2-product-launcher-application</name>
<packaging>jar</packaging>

<properties>
    <java.version>11</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents.client5</groupId>
        <artifactId>httpclient5</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <!-- This copies the JRE used to do the build from java.home - should 
                be 32 bit Windows JRE -->
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <!-- here the phase you need -->
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/win32/java</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${java.home}</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.akathist.maven.plugins.launch4j</groupId>
            <artifactId>launch4j-maven-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <id>l4j-clui</id>
                    <phase>package</phase>
                    <goals>
                        <goal>launch4j</goal>
                    </goals>
                    <configuration>
                        <headerType>gui</headerType>
                        <jar>${project.build.directory}/${artifactId}-${version}.jar</jar>
                        <outfile>${project.build.directory}/KPIT_Vehicle_Diagnostics.exe</outfile>
                        <!-- <downloadUrl>http://java.com/download</downloadUrl> -->
                        <stayAlive>true</stayAlive>
                        <!-- <classPath> <mainClass>org.springframework.boot.loader.JarLauncher</mainClass> 
                            <addDependencies>true</addDependencies> <preCp>anything</preCp> </classPath> -->
                        <jre>
                            <!-- <minVersion>1.8.0</minVersion> -->
                            <!-- <jdkPreference>preferJre</jdkPreference> -->
                            <path>./jre</path>
                        </jre>
                        <versionInfo>
                            <fileVersion>1.0.0.0</fileVersion>
                            <txtFileVersion>1.0.0.0</txtFileVersion>
                            <fileDescription>KPIT Vehicle Diagnostics</fileDescription>
                            <copyright>Copyright (c) 2018-2021 KPIT Technologies GmbH</copyright>
                            <productVersion>1.0.0.0</productVersion>
                            <txtProductVersion>1.0.0.0</txtProductVersion>
                            <productName>KPIT Vehicle Diagnostics</productName>
                            <companyName>KPIT</companyName>
                            <internalName>KPIT</internalName>
                            <originalFilename>KPIT Vehicle Diagnostics.exe</originalFilename>
                        </versionInfo>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<profiles>
    <profile>
        <id>native</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.graalvm.buildtools</groupId>
                    <artifactId>native-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>build-native</id>
                            <goals>
                                <goal>compile-no-fork</goal>
                            </goals>
                            <phase>package</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <mainClass>com.kpit.tf2.configuration.Application</mainClass>
                        <buildArgs>
                            <buildArg>-H:Class=com.kpit.tf2.configuration.Application</buildArg>
                            <buildArg>-H:-CheckToolchain</buildArg>
                            <buildArg>-H:+ReportExceptionStackTraces</buildArg>
                            <buildArg>--initialize-at-build-time=ch.qos.logback</buildArg>
                            <buildArg>-H:ReflectionConfigurationFiles=src/main/resources/reflection-config.json</buildArg>
                        </buildArgs>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

The logack.xml file <?xml version="1.0" encoding="UTF-8"?>

%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n

The application.properties file contains only server.port=9090

The Application. java is the main claas

command I am using to create exe - mvn clean package -Pnative

The screenshot of exe generated image

The screenshot of exe running file image

Expectation : Server is keep on running on port 9090 Can someone please help me here.

abhijeeta94 commented 6 months ago

Any comments for the Issue?

ghotm commented 3 months ago

I had the same problem, but I used this command and it worked for me mvn native:compile -Pnative

pom

<dependencies>
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
  </dependency>
 </dependencies>

 <build>
  <plugins>
      <plugin>
          <groupId>org.graalvm.buildtools</groupId>
          <artifactId>native-maven-plugin</artifactId>
          <version>0.10.1</version>
          <configuration>
              <skip>false</skip>
              <verbose>true</verbose>
              <quickBuild>true</quickBuild>
              <buildArgs>
                  -H:-CheckToolchain
                  --no-fallback
                  --initialize-at-build-time=ch.qos.logback
                  --initialize-at-build-time=org.slf4j
                  --enable-preview
              </buildArgs>
              <mainClass>xxx.xxx.xxxApplication</mainClass>
          </configuration>
      </plugin>
      <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <configuration>
              <mainClass>xxx.xxx.xxxApplication</mainClass>
          </configuration>
      </plugin>
  </plugins>
 </build>