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

Could not find or load main class org.springframework.boot.loader.JarLauncher #184

Closed
donkahlero opened this issue Jan 17, 2024 · 4 comments
Labels

Comments

@donkahlero
Copy link

Hello dear maintanance team,

currently, I am trying to move away from a gradle-base Spring Cloud Functions build towards a bazel build.

My configuration looks as follows:

MODULES.bzl

[...]
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
    artifacts = [
        "com.amazonaws:aws-lambda-java-events:3.11.1",
        "com.fasterxml.jackson.core:jackson-annotations:2.16.1",
        "com.google.code.gson:gson:2.10.1",
        "io.swagger.core.v3:swagger-annotations:2.2.18",
        "jakarta.validation:jakarta.validation-api:3.0.2",
        "org.apache.logging.log4j:log4j-core:2.20.0",
        "org.mapstruct:mapstruct-processor:1.5.5.Final",
        "org.mapstruct:mapstruct:1.5.5.Final",
        "org.projectlombok:lombok:1.18.30",
        "org.springframework.boot:spring-boot-starter-web:3.1.2",
        "org.springframework.cloud:spring-cloud-function-adapter-aws:4.0.4",
        "org.springframework.cloud:spring-cloud-function-context:4.0.4",
        "software.amazon.awssdk:lambda:2.23.2",
    ],
    fetch_sources = True,
    repositories = [
        "https://some_internal_maven_mirror",
    ],
)
use_repo(maven, "maven")
[...]

BUILD

load("@rules_spring//springboot:springboot.bzl", "springboot")
[...]
deps = [
    "@maven//:com_amazonaws_aws_lambda_java_events",
    "@maven//:com_google_code_gson_gson",
    "@maven//:jakarta_validation_jakarta_validation_api",
    "@maven//:org_apache_logging_log4j_log4j_api",
    "@maven//:org_apache_logging_log4j_log4j_core",
    "@maven//:org_springframework_boot_spring_boot",
    "@maven//:org_springframework_boot_spring_boot_autoconfigure",
    "@maven//:org_springframework_boot_spring_boot_starter_web",
    "@maven//:org_springframework_cloud_spring_cloud_function_adapter_aws",
    "@maven//:org_springframework_cloud_spring_cloud_function_context",
    "@maven//:org_springframework_spring_context",
    "@maven//:org_springframework_spring_core",
    "@maven//:org_springframework_spring_web",
    "@maven//:software_amazon_awssdk_regions",
]

java_library(
    name = "_function",
    srcs = [...],
    deps = [SOME_INTERNAL_DEPS] + deps,
    resources = glob(["src/main/resources/**"]),
)

springboot(
    name = "function",
    boot_app_class = "path.to.my.main.Class",
    java_library = ":_function",
)

However, if try to execute my spring application, I am getting this result:

Error: Could not find or load main class org.springframework.boot.loader.JarLauncher
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.loader.JarLauncher

I saw that there has been an issue in the past (#13) but that has been marked resolved after some PRs.

What I am doing wrong here? What am I missing? Are Spring Cloud Functions even supported?

Cheers and thanks for your help!
Jonas

@plaird
Copy link
Contributor

plaird commented Jan 17, 2024

rules_spring took a BYOSD (bring your own spring dependencies) approach because we didn't want to lock you into a particular version of anything. We require you to add all the required Spring/SpringBoot dependencies to the deps list.

This includes the foundation Spring Boot "loader" jar which knows how to launch a Spring Boot app. The problem is you are missing that.

You are missing this lib from your deps list: org.springframework.boot:spring-boot-loader

Or, for convenience, we have an "import bundle" that defines the min set of dependencies:
Spring Boot import bundle example

Please use one of the above solution and let us know how it goes.

@plaird plaird changed the title Spring Cloud Functions Issue Could not find or load main class org.springframework.boot.loader.JarLauncher Jan 17, 2024
@plaird
Copy link
Contributor

plaird commented Jan 17, 2024

(I revised the title of this Issue to reflect the actual error. I don't think this is related to Spring Cloud at all)

@donkahlero
Copy link
Author

Hi @plaird,
thanks for getting back to me. I actually found that out myself, but you were slightly faster than me in answering. Sorry for that!

However, there is some other issue with the spring cloud functions deployment on AWS that I am investigating at the moment and I will update this issue for anyone that is interested in this as soon as I know more.

@plaird
Copy link
Contributor

plaird commented Jan 30, 2024

FYI: If you arrive here by looking at the title, and are using Spring Boot 3, the issue you are facing might be:
#177

@plaird plaird closed this as completed Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants