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

Trouble Running Spring Boot Application from Jar with Included Dependencies for fast startup #40833

Closed
Mohamed-Hammada opened this issue May 20, 2024 · 1 comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid

Comments

@Mohamed-Hammada
Copy link

I'm encountering an issue when trying to run a Spring Boot application from a jar file that includes its dependencies. Here's my setup:

I've created a new Spring Boot Gradle application and configured the jar task in my build.gradle file to include dependencies inside the generated jar file using the following snippet:

jar {
    archiveFileName = "${project.name}-test.jar"
    zip64 = true
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
        attributes 'Main-Class': 'com.example.demo.DemoApplication'
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

The jar file is generated successfully. However, when I try to run the generated jar using java -jar demo.jar, it starts but immediately stops. Interestingly, if I use bootJar, the application runs perfectly.

My goal is to improve startup time, and I've explored solutions like GraalVM. However, compatibility issues arise with dependencies such as Log4j, Flyway, and Liquibase, especially considering that my project has multiple modules with their own dependencies.

When I tried the same approach mentioned above with another project, I encountered different issues:

Error: Could not find or load main class mobi.foo.yeepalwallet.FooApplication
Caused by: java.lang.ClassNotFoundException: dd.ss.main.class

I attempted to utilize the Shadow library (com.github.johnrengelman.shadow), but encountered numerous errors. Despite this, I managed to execute the generated JAR, albeit with different errors.

You can generate the Spring Boot project using the following link: Spring Initializr

I'm seeking guidance on the correct approach to achieve faster application startup time while including dependencies in the jar. Any insights or suggestions would be greatly appreciated. Thank you.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 20, 2024
@wilkinsona
Copy link
Member

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

You may also want to read the documentation on efficient deployments.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants