I have created a simple repository which has two functions:
- Greets the user.
- Asks for a username, saves it to the
postgresqldatabase, 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);
}
}
clean build. But for heroku, I don't know where to set itbuild/libs/*.jarwill have two jars, one plain. Did you check the directory content?