You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Micronaut应用Docker镜像构建失败:主入口类未找到

Troubleshooting "Main entry point class not found" Error When Building Micronaut AWS Custom Runtime Docker Image

I’ve run into similar headaches when building Micronaut AWS custom runtime images with GraalVM native image, so let’s break down what might be going wrong and how to fix it.

First, to recap your scenario: your Micronaut app runs perfectly locally, but when you run docker build . -t student-custom-runtime, the native-image step fails with Main entry point class 'io.micronaut.function.aws.runtime.MicronautLambdaRuntime' not found—even though you’ve confirmed the micronaut-function-aws-custom-runtime jar is in your local dependencies.

Here are the most likely fixes to try:

1. Fix the Classpath in Your native-image Command

Looking at your build-native-image.sh, the --class-path parameter only includes your app’s jar (student-custom-runtime-*.jar), but it doesn’t pull in dependent jars like micronaut-function-aws-custom-runtime.jar. GraalVM native-image needs all required classes in the classpath to locate the entry point.

Solution:

Update the classpath to include all dependencies. If your Docker build copies dependencies into a lib directory (a common setup), modify the line to:

--class-path "student-custom-runtime-*.jar:lib/*" \

If you’re using Gradle or Maven, you can also skip manual classpath setup entirely by using Micronaut’s built-in native-image tasks. For example, running ./gradlew nativeImage with Gradle will automatically assemble the correct classpath for you.

2. Ensure Dependencies Are Copied to the Docker Build Context

Even if your local project has all the right jars, your Dockerfile might not be copying them into the build environment. If the micronaut-function-aws-custom-runtime.jar isn’t present in the Docker container when running native-image, it can’t find the class.

Solution:

Check your Dockerfile for steps that copy dependencies. For example:

  • If using Gradle, add a step like:
    COPY build/libs/lib /app/lib
    
  • If using Maven, add:
    COPY target/dependency /app/lib
    

Make sure these steps run before executing build-native-image.sh, so the jars are available in the container’s filesystem.

3. Verify GraalVM Version Compatibility

Micronaut and GraalVM have strict version compatibility rules. Using an incompatible GraalVM version can lead to weird classpath issues or missing classes.

Solution:

  • Cross-check the Micronaut documentation (no external links needed—just confirm version matches) for the GraalVM version required by your Micronaut version. For example, Micronaut 4.x requires GraalVM 22.3+.
  • Ensure your Docker image uses the correct GraalVM base image. For Java 17, use something like:
    FROM ghcr.io/graalvm/graalvm-ce:22.3-java17
    
  • Add a step in your Dockerfile to confirm the version: ${GRAALVM_HOME}/bin/java -version to make sure it’s what you expect.

4. Test the native-image Command Locally First

To rule out Docker-specific issues, run your build-native-image.sh locally (outside Docker). If it fails with the same error, the problem is in your classpath or GraalVM setup. If it succeeds, the issue is definitely in how Docker is copying dependencies or setting up the environment.

Bonus: Double-Check the Entry Point Class

While you confirmed the jar exists, take a quick second to verify the class name is exactly correct. The full path should be io.micronaut.function.aws.runtime.MicronautLambdaRuntime—watch for typos like missing function or runtime in the package name.

Try these steps one by one, and you should be able to resolve the class not found error.

内容的提问来源于stack exchange,提问作者nehacharya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:26:53