graalvm / native-build-tools

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

Error: Main entry point class 'com.example.Application' neither found on classpath (spring boot maven multiple submodule) #585

Open TinCongHuynh opened 3 months ago

TinCongHuynh commented 3 months ago

Hi,

I am facing with an error when building native image using graalvm. ALWAYS ALWAYS got this error

GraalVM Native Image: Generating 'rxbatch' (executable)...
========================================================================================================================
[1/8] Initializing...                                                                                    (0.0s @ 0.12GB)
Error: Main entry point class 'com.example.Application' neither found on 
classpath: '/Users/huynhcongtin/Downloads/rxbatch_graalvm/target/classes:

I tried with 2 ways to build, but both got same error

  1. Config native-maven-plugin in pom file and run command
    mvn -Pnative native:compile
  2. Build jar file without native, then compile native using native-image
    native-image --no-fallback -J-Xmx3072m -H:Name=rxbatch -cp rxbatch-webapp/target/rxbatch-webapp-1.0-SNAPSHOT.jar com.example.App

Here are some info

My spring boot maven project is structured under submodule

<modules>
    <module>rxbatch-webapp</module>
    <module>rxbatch-core</module>
    <module>rxbatch-service</module>
  </modules>

The main class was put into rxbatch-webapp sub module

Here is the parent pom.xml file

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.3</version>
    <relativePath/>                         <!-- lookup parent from repository -->
  </parent>
  <packaging>pom</packaging>
  <groupId>com.example</groupId>
  <artifactId>rxbatch</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>rxbatch_graalvm</name>
  <description>Demo project for Spring Boot</description>

  <properties>
    <java.version>21</java.version>
    <start-class>com.example.Application</start-class>
  </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>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.graalvm.buildtools</groupId>
        <artifactId>native-maven-plugin</artifactId>
        <version>0.10.1</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <id>build-native</id>
            <goals>
              <goal>compile-no-fork</goal>
            </goals>
            <phase>package</phase>
          </execution>
          <execution>
            <id>test-native</id>
            <goals>
              <goal>test</goal>
            </goals>
            <phase>test</phase>
          </execution>
        </executions>
        <configuration>
          <!-- Mockito is not supported -->
          <skipNativeTests>true</skipNativeTests>
          <mainClass>com.example.Application</mainClass> <!-- Specify your main class -->
        </configuration>
      </plugin>

    </plugins>

  </build>
  <modules>
    <module>rxbatch-webapp</module>
    <module>rxbatch-core</module>
    <module>rxbatch-service</module>
  </modules>
</project>

Here is the pom.xml of submodule rxbatch-webapp

<?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">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>rxbatch</artifactId>
    <groupId>com.example</groupId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>

  <artifactId>rxbatch-webapp</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>rxbatch-webapp</name>
  <url>http://www.example.com</url>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.2</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.example.Application</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <mainClass>com.example.Application</mainClass>
        </configuration>
      </plugin>

    </plugins>
  </build>
</project>

I don't know why above error happen even I checked my main class existing in jar file

jar tf rxbatch-webapp-1.0-SNAPSHOT.jar | grep com.example.App

Moreover I can build native image successfully with spring boot maven single module (no submodule)

Please help to advice this case

This is my project https://github.com/TinCongHuynh/graalvm-springboot-maven-submodule