1

I have created a simple repository which has two functions:

  1. Greets the user.
  2. Asks for a username, saves it to the postgresql database, greets the user by this name.

When I test my application locally, it works correctly. But when I try to deploy it to Heroku, I get these errors:

heroku[web.1]: Starting process with command java -Dserver.port=11441 $JAVA_OPTS -jar build/libs/*.jar
app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8 
app[web.1]: Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
app[web.1]:     at com.pro.library.Application.main(Application.java:10)
app[web.1]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
app[web.1]:     at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
app[web.1]:     at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
app[web.1]:     at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)

I have a feeling that the error is related to the creation of the jar, but I do not understand how to solve it. I have already looked at a bunch of articles on how to deploy to heroku, but so far this has not helped to identify my problem.

my Procfile:

web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/*.jar

my building.gradle.kts:

plugins {
    java
    id("org.springframework.boot") version "2.7.1"
    id("io.spring.dependency-management") version "1.1.0"
}

version = "0.0.1"
java.sourceCompatibility = JavaVersion.VERSION_11

configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

repositories {
    mavenCentral()
    maven { url = uri("https://repo.spring.io/milestone") }
    maven { url = uri("https://repo.spring.io/snapshot") }
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.7.9")
    implementation("org.springframework.boot:spring-boot-starter-web:2.7.9")

    compileOnly("org.projectlombok:lombok:1.18.26")
    annotationProcessor("org.projectlombok:lombok:1.18.26")
    implementation("org.mapstruct:mapstruct:1.5.3.Final")
    annotationProcessor("org.mapstruct:mapstruct-processor:1.5.3.Final")

    implementation("org.postgresql:postgresql:42.5.4")
    implementation("org.flywaydb:flyway-core:8.5.13")
    implementation("com.vladmihalcea:hibernate-types-52:2.20.0")

    testImplementation("org.springframework.boot:spring-boot-starter-test:2.7.9")
    testImplementation("org.testcontainers:testcontainers:1.17.6")
    testImplementation("org.testcontainers:postgresql:1.17.6")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.jar {
    manifest {
        attributes(
            "Main-Class" to "com.pro.library.Application",
        )
    }
}

My Application.java

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
4
  • Which command do you use to build the application? Commented Mar 27, 2023 at 8:02
  • locally: standard clean build. But for heroku, I don't know where to set it Commented Mar 27, 2023 at 11:23
  • Most probably build/libs/*.jar will have two jars, one plain. Did you check the directory content? Commented Mar 28, 2023 at 0:53
  • Did you get this resolved? I am facing the same issue while getting set up. The build command is not creating a bootable JAR, and I am unsure how to resolve this. Commented Feb 23 at 4:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.