Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Spring boot native image failed #370

Open
sendev1 opened this issue Jul 20, 2020 · 2 comments
Open

Spring boot native image failed #370

sendev1 opened this issue Jul 20, 2020 · 2 comments

Comments

@sendev1
Copy link

sendev1 commented Jul 20, 2020

What happened?

I have a simple spring boot application which is running fine in spring boot mode in Intellij or as a jar. Please see below for the logs

C:\`\apps\z_study_spring-boot-web-graal-vm\build\libs>java -jar graal-vm-0.0.1-SNAPSHOT.jar com.palantir.test.Main

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

2020-07-20 16:33:17.550  INFO 25052 --- [           main] com.palantir.test.Main                   : Starting Main on BGTMNWL-9123HKG with PID 25052 (C:\`\apps\z_study_spring-boot-web-graal-vm\build\libs\graal-vm-0.0.1-SNAPSHOT.jar started by URAJAS4 in C:\`\apps\z_study_spring-boot-web-graal-vm\build\libs)
2020-07-20 16:33:17.554  INFO 25052 --- [           main] com.palantir.test.Main                   : No active profile set, falling back to default profiles: default
2020-07-20 16:33:20.009  INFO 25052 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-07-20 16:33:20.031  INFO 25052 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-07-20 16:33:20.031  INFO 25052 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.36]
2020-07-20 16:33:20.178  INFO 25052 --- [           main] o.a.c.c.C.[.[localhost].[/graal-vm]      : Initializing Spring embedded WebApplicationContext
2020-07-20 16:33:20.178  INFO 25052 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2531 ms
2020-07-20 16:33:20.540  INFO 25052 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-07-20 16:33:20.806  INFO 25052 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path '/graal-vm'
2020-07-20 16:33:20.821  INFO 25052 --- [           main] **com.palantir.test.Main**                   : Started Main in 4.051 seconds (JVM running for 4.845)

But when I try to create native image using plug in I see following error

Warning: Ignoring server-mode native-image argument --no-server.
[hello-graal:17932]    classlist:   8,357.64 ms,  1.37 GB
Error: Main entry point class 'com.palantir.test.Main' not found.
com.oracle.svm.core.util.UserError$UserException: Main entry point class 'com.palantir.test.Main' not found.
        at com.oracle.svm.core.util.UserError.abort(UserError.java:68)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:302)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:518)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:117)

Error: Image build request failed with exit status 1

As you can see from the spring boot jar version log the main class is under package com.palantir.test.Main . Not sure why the plugin is complaining that its not able to find main class.

Here is the build.gradle entry

graal {
	mainClass 'com.palantir.test.Main'
	outputName 'hello-graal'
	graalVersion '20.1.0'
	option '-H:+ReportExceptionStackTraces'
}

What did you want to happen?

native image should be created for spring boot version 2.3.1.RELEASE or any spring boot version supported by Graal

@maffelbaffel
Copy link

Hm might this be because of using bootJar instead of jar? I'm trying out this plugin right now and I get the same problem.
Using gradle bootJar my classes are package inside of BOOT-INF/classes while with a simple jar they are package in root of the jar file.

@jUnG3
Copy link

jUnG3 commented Sep 8, 2020

Hi,
I have the same problem as @sendev1. When I try to build my project with ./gradlew clean build nativeImage i get this error message: Error: Main entry point class 'de.hello.Application.' not found..

Here is my build.gradle

plugins {
    id 'org.springframework.boot' version '2.2.9.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
    id 'application'
    id 'com.palantir.graal' version '0.7.1-20-g113a84d'
}

apply plugin: 'java'
apply plugin: 'application'

group = 'de.hello'
version = '0.0.1'
sourceCompatibility = '8'
mainClassName = 'de.hello.Application'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'tel.schich:javacan:2.1.0'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

graal {
    mainClass 'de.hello.Application'
    graalVersion '20.1.0'
    outputName 'hello'
    option '-H:+ReportExceptionStackTraces'
}

Hm might this be because of using bootJar instead of jar? I'm trying out this plugin right now and I get the same problem.
Using gradle bootJar my classes are package inside of BOOT-INF/classes while with a simple jar they are package in root of the jar file.

How can I use the jar task instead of bootJar? @maffelbaffel can you please post the workaround?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants