Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abhijeeta94 opened this issue Dec 21, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@abhijeeta94
Copy link

Please refer below pom.xml file which I am using


4.0.0


org.springframework.boot
spring-boot-starter-parent
3.2.0

com.kpit.diagnostics.tf2
tf2-product-launcher-application
1.0.0-SNAPSHOT
tf2-product-launcher-application
jar

<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

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
	<layout class="ch.qos.logback.classic.PatternLayout">
		<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
		</Pattern>
	</layout>
</appender>

<property name="LOG_HOME" value="logs" />
<property name="MIN_INDEX" value="1" />
<property name="MAX_ZIP_FILES" value="10" />

<root level="WARN">
	<appender-ref ref="FILE" level="ERROR" />
	<appender-ref ref="STDOUT" level="ERROR" />
</root>
<logger name="com.kpit" level="DEBUG" additivity="true">
	<appender-ref ref="STDOUT" level="WARNING" />
</logger>
<logger name="com.kpit" level="TRACE" additivity="false">
	<appender-ref ref="STDOUT" level="WARNING" />
</logger>

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 abhijeeta94 added the bug Something isn't working label Dec 21, 2023
@abhijeeta94
Copy link
Author

Any comments for the Issue?

@ghotm
Copy link

ghotm commented Mar 17, 2024

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants