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

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

Open
TinCongHuynh opened this issue Mar 20, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@TinCongHuynh
Copy link

TinCongHuynh commented Mar 20, 2024

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
  1. 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

  • java version "21.0.2" 2024-01-16 LTS
  • Java(TM) SE Runtime Environment Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30)
  • Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30, mixed mode, sharing)
  • Spring boot version 3.2.3

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

@TinCongHuynh TinCongHuynh added the question Further information is requested label Mar 20, 2024
@rvaidya
Copy link

rvaidya commented Aug 7, 2024

I am also experiencing this, the plugin is looking for a main class/method in every module, when it doesn't exist in modules that contain shared code that are used as dependencies for top level modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants