Issue
I want to deploy my spring boot application to Heroku, I followed the steps and created the jar file - Survey-0.0.1-SNAPSHOT.jar. The app works fine locally, also running the app by:
heroku local web
works fine. Running the jar file using
java -jar target/Survey-0.0.1-SNAPSHOT.jar
also works fine showing:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-05-08 15:36:07.685 INFO 23710 --- [ main] survey.SurveyApplication : Starting SurveyApplication v0.0.1-SNAPSHOT using Java 16.0.1 on karthikey with PID 23710 (/home/karthikey/Desktop/JavaPrograms/Survey/target/Survey-0.0.1-SNAPSHOT.jar started by karthikey in /home/karthikey/Desktop/JavaPrograms/Survey)
2021-05-08 15:36:07.688 INFO 23710 --- [ main] survey.SurveyApplication : No active profile set, falling back to default profiles: default
2021-05-08 15:36:08.455 INFO 23710 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-05-08 15:36:08.534 INFO 23710 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 69 ms. Found 4 JPA repository interfaces.
2021-05-08 15:36:08.925 INFO 23710 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@4e423aa2' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-08 15:36:08.928 INFO 23710 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-08 15:36:09.188 INFO 23710 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-05-08 15:36:09.200 INFO 23710 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-08 15:36:09.200 INFO 23710 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-05-08 15:36:09.247 INFO 23710 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-08 15:36:09.247 INFO 23710 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1513 ms
2021-05-08 15:36:09.334 WARN 23710 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-05-08 15:36:09.476 INFO 23710 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-05-08 15:36:09.537 INFO 23710 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.30.Final
2021-05-08 15:36:09.659 INFO 23710 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-05-08 15:36:09.758 INFO 23710 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-05-08 15:36:14.569 INFO 23710 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-05-08 15:36:14.588 INFO 23710 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2021-05-08 15:36:17.448 INFO 23710 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-05-08 15:36:17.460 INFO 23710 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-05-08 15:36:18.357 INFO 23710 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@2f7efd0b, org.springframework.security.web.context.SecurityContextPersistenceFilter@53a7a60c, org.springframework.security.web.header.HeaderWriterFilter@3ae126d1, org.springframework.web.filter.CorsFilter@41ad373, org.springframework.security.web.authentication.logout.LogoutFilter@326d27ac, survey.security.jwt.AuthTokenFilter@1a1f5f71, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@6a87026, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@2503ec73, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@6801b414, org.springframework.security.web.session.SessionManagementFilter@43fda8d9, org.springframework.security.web.access.ExceptionTranslationFilter@3e4e4c1, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@69f0b0f4]
2021-05-08 15:36:18.434 INFO 23710 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-08 15:36:18.598 INFO 23710 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-08 15:36:18.608 INFO 23710 --- [ main] survey.SurveyApplication : Started SurveyApplication in 11.38 seconds (JVM running for 11.803)
But when I push my app using
git push heroku master
the app is successfully built showing:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 310 bytes | 310.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/java
remote: -----> Java app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Executing Maven
remote: $ ./mvnw -DskipTests clean dependency:list install
remote: [INFO] Scanning for projects...
remote: [INFO]
remote: [INFO] -------------------------< com.example:Survey >-------------------------
remote: [INFO] Building Survey 0.0.1-SNAPSHOT
remote: [INFO] --------------------------------[ jar ]---------------------------------
remote: [INFO]
remote: [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ Survey ---
remote: [INFO]
remote: [INFO] --- maven-dependency-plugin:3.1.2:list (default-cli) @ Survey ---
remote: [INFO]
remote: [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ Survey ---
remote: [INFO] Using 'UTF-8' encoding to copy filtered resources.
remote: [INFO] Using 'UTF-8' encoding to copy filtered properties files.
remote: [INFO] Copying 1 resource
remote: [INFO] Copying 2 resources
remote: [INFO]
remote: [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ Survey ---
remote: [INFO] Changes detected - recompiling the module!
remote: [INFO] Compiling 27 source files to /tmp/build_f97fc166/target/classes
remote: [INFO]
remote: [INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ Survey ---
remote: [INFO] Using 'UTF-8' encoding to copy filtered resources.
remote: [INFO] Using 'UTF-8' encoding to copy filtered properties files.
remote: [INFO] skip non existing resourceDirectory /tmp/build_f97fc166/src/test/resources
remote: [INFO]
remote: [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ Survey ---
remote: [INFO] Changes detected - recompiling the module!
remote: [INFO] Compiling 1 source file to /tmp/build_f97fc166/target/test-classes
remote: [INFO]
remote: [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ Survey ---
remote: [INFO] Tests are skipped.
remote: [INFO]
remote: [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ Survey ---
remote: [INFO] Building jar: /tmp/build_f97fc166/target/Survey-0.0.1-SNAPSHOT.jar
remote: [INFO]
remote: [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ Survey ---
remote: [INFO] Installing /tmp/build_f97fc166/target/Survey-0.0.1-SNAPSHOT.jar to /tmp/codon/tmp/cache/.m2/repository/com/example/Survey/0.0.1-SNAPSHOT/Survey-0.0.1-SNAPSHOT.jar
remote: [INFO] Installing /tmp/build_f97fc166/pom.xml to /tmp/codon/tmp/cache/.m2/repository/com/example/Survey/0.0.1-SNAPSHOT/Survey-0.0.1-SNAPSHOT.pom
remote: [INFO] ------------------------------------------------------------------------
remote: [INFO] BUILD SUCCESS
remote: [INFO] ------------------------------------------------------------------------
remote: [INFO] Total time: 5.861 s
remote: [INFO] Finished at: 2021-05-08T08:34:54Z
remote: [INFO] ------------------------------------------------------------------------
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 51.9M
remote: -----> Launching...
remote: Released v34
remote: https://survey-it-up.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/survey-it-up.git
1dddca6..dfc71c2 master -> master
But, on opening the app I get an Application Error. My Heroku logs show:
2021-05-08T08:28:30.262404+00:00 heroku[web.1]: Starting process with command `java -jar target/Survey-0.0.1-SNAPSHOT.jar`
2021-05-08T08:28:33.256619+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-05-08T08:28:33.267118+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-05-08T08:28:34.111253+00:00 app[web.1]: no main manifest attribute, in target/Survey-0.0.1-SNAPSHOT.jar
2021-05-08T08:28:34.221069+00:00 heroku[web.1]: Process exited with status 1
2021-05-08T08:28:34.316998+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-08T08:28:41.429441+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=survey-it-up.herokuapp.com request_id=88005eec-9e4c-4cd0-9c15-e2f69139a5aa fwd="157.47.209.28" dyno= connect= service= status=503 bytes= protocol=https
2021-05-08T08:28:41.812244+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=survey-it-up.herokuapp.com request_id=880bb93c-4805-4436-b70d-0fb1136cbd59 fwd="157.47.209.28" dyno= connect= service= status=503 bytes= protocol=https
My Procfile:
web: java -jar target/Survey-0.0.1-SNAPSHOT.jar
I have also specified the main class in the MANIFEST.MF file and it works fine locally. My MANIFEST.MF file:
Manifest-Version: 1.0
Created-By: Maven Jar Plugin 3.2.0
Build-Jdk-Spec: 16
Implementation-Title: Survey
Implementation-Version: 0.0.1-SNAPSHOT
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: survey.SurveyApplication
Spring-Boot-Version: 2.4.5
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>Survey</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Survey</name>
<description>A web application for hoisting surveys</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I think when deploying to Heroku, it runs:
mvn clean install
and it changes the MANIFEST.MF file somehow, like taking the default MANIFEST.MF which doesn't contain main class property. I don't understand why it gives no main manifest error even after specifying the main class. Please help me out.
Solution
I resolved the error by removing the <pluginManagement>
under the build section of the pom.xml file. Seems like Heroku was not reading the <pluginManagement>
, after removing it the app got successfully deployed to Heroku. I followed the following steps after removing the tag:
mvn package
The above command builds the project and packages the resulting JAR file into the target directory, and then run
git push heroku master
to push the app to Heroku.
Note: I enclosed the plugins under <pluginManagement>
because Eclipse was showing an error on plugins, but even then the program still ran. So it seems there was no requirement for the <pluginManagement>
tag.
Answered By - Karthikey Saxena