Caused by java lang classnotfoundexception org springframework boot springapplication

Spring Boot deployment — NoClassDefFoundError

I’m trying to deploy Spring Boot application. I build a jar file through maven plugins. But I get an error saying:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication at com.spring-boot.example.AppConfig.main(AppConfig.java:18) Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) . 1 more 

I tried adding additional plugins to the pom.xml file, but none of it worked. Any help will be very appreciated. This is my pom.xml file:

  4.0.0 com.spring-boot.example spring-boot-example 0.1 1.8 UTF-8 com.spring-boot.example.AppConfig 4.0.7.RELEASE 1.2.17 1.7  org.springframework.boot spring-boot-starter-parent 1.1.9.RELEASE   org.springframework.boot spring-boot-starter-web  org.springframework.boot spring-boot-starter-actuator  org.springframework.boot spring-boot-starter-test test  org.hibernate hibernate-validator  org.springframework spring-test test  org.springframework spring-jdbc 4.2.0.RELEASE  org.springframework.boot spring-boot-starter-jdbc 1.2.1.RELEASE  org.springframework.boot spring-boot-starter-tomcat provided     org.springframework.boot spring-boot-maven-plugin     

Источник

Spring boot not running on Heroku

So I have a spring boot application build with Gradle. It’s working just fine when build and run locally, however, I can’t make it run on Heroku. Here are the logs:

2018-03-10T22:24:19.561282+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=53342 $JAVA_OPTS -jar build/libs/*.jar` 2018-03-10T22:24:21.446741+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile 2018-03-10T22:24:21.458097+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them. 2018-03-10T22:24:21.461370+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8 2018-03-10T22:24:21.701767+00:00 app[web.1]: Exception in thread "main" java.lang.reflect.InvocationTargetException 2018-03-10T22:24:21.701779+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2018-03-10T22:24:21.701781+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 2018-03-10T22:24:21.701783+00:00 app[web.1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2018-03-10T22:24:21.701784+00:00 app[web.1]: at java.lang.reflect.Method.invoke(Method.java:498) 2018-03-10T22:24:21.701786+00:00 app[web.1]: at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) 2018-03-10T22:24:21.701788+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) 2018-03-10T22:24:21.701789+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) 2018-03-10T22:24:21.701792+00:00 app[web.1]: Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication 2018-03-10T22:24:21.701791+00:00 app[web.1]: at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) 2018-03-10T22:24:21.701794+00:00 app[web.1]: at com.bristech.BristechApp.main(BristechApp.java:12) 2018-03-10T22:24:21.701795+00:00 app[web.1]: . 8 more 2018-03-10T22:24:21.701797+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication 2018-03-10T22:24:21.701798+00:00 app[web.1]: at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 2018-03-10T22:24:21.701800+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 2018-03-10T22:24:21.701802+00:00 app[web.1]: at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) 2018-03-10T22:24:21.701804+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 2018-03-10T22:24:21.701805+00:00 app[web.1]: . 9 more 2018-03-10T22:24:21.828827+00:00 heroku[web.1]: Process exited with status 1 2018-03-10T22:24:21.845444+00:00 heroku[web.1]: State changed from starting to crashed 2018-03-10T22:24:21.848108+00:00 heroku[web.1]: State changed from crashed to starting 2018-03-10T22:24:24.295261+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=48859 $JAVA_OPTS -jar build/libs/*.jar` 2018-03-10T22:24:25.862214+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them. 2018-03-10T22:24:25.849109+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile 2018-03-10T22:24:25.865381+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8 2018-03-10T22:24:26.065973+00:00 app[web.1]: Exception in thread "main" java.lang.reflect.InvocationTargetException 2018-03-10T22:24:26.066210+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2018-03-10T22:24:26.066306+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 2018-03-10T22:24:26.066354+00:00 app[web.1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2018-03-10T22:24:26.066402+00:00 app[web.1]: at java.lang.reflect.Method.invoke(Method.java:498) 2018-03-10T22:24:26.066464+00:00 app[web.1]: at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) 2018-03-10T22:24:26.066593+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) 2018-03-10T22:24:26.066532+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) 2018-03-10T22:24:26.066651+00:00 app[web.1]: at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) 2018-03-10T22:24:26.066845+00:00 app[web.1]: Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication 2018-03-10T22:24:26.067057+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication 2018-03-10T22:24:26.066918+00:00 app[web.1]: at com.bristech.BristechApp.main(BristechApp.java:12) 2018-03-10T22:24:26.066974+00:00 app[web.1]: . 8 more 2018-03-10T22:24:26.067098+00:00 app[web.1]: at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 2018-03-10T22:24:26.067138+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 2018-03-10T22:24:26.067221+00:00 app[web.1]: at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) 2018-03-10T22:24:26.067225+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 2018-03-10T22:24:26.067285+00:00 app[web.1]: . 9 more 2018-03-10T22:24:26.176301+00:00 heroku[web.1]: Process exited with status 1 2018-03-10T22:24:26.195791+00:00 heroku[web.1]: State changed from starting to crashed 2018-03-10T22:35:56.000000+00:00 app[api]: Build started by user bris47degrees@gmail.com 2018-03-10T22:36:30.552290+00:00 app[api]: Release v4 created by user bris47degrees@gmail.com 2018-03-10T22:36:30.552290+00:00 app[api]: Deploy eb0b8be4 by user bris47degrees@gmail.com 2018-03-10T22:35:56.000000+00:00 app[api]: Build succeeded 2018-03-10T22:36:31.291066+00:00 heroku[web.1]: State changed from crashed to starting 2018-03-10T22:36:34.505370+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/bristech.jar` 2018-03-10T22:36:36.916160+00:00 heroku[web.1]: State changed from starting to crashed 2018-03-10T22:36:36.918820+00:00 heroku[web.1]: State changed from crashed to starting 2018-03-10T22:36:36.899817+00:00 heroku[web.1]: Process exited with status 1 2018-03-10T22:36:36.830058+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them. 2018-03-10T22:36:36.831354+00:00 app[web.1]: Error: Unable to access jarfile build/libs/bristech.jar 2018-03-10T22:36:39.908150+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/bristech.jar` 2018-03-10T22:36:41.758247+00:00 heroku[web.1]: Process exited with status 1 2018-03-10T22:36:41.698096+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them. 2018-03-10T22:36:41.700091+00:00 app[web.1]: Error: Unable to access jarfile build/libs/bristech.jar 2018-03-10T22:36:41.771761+00:00 heroku[web.1]: State changed from starting to crashed 2018-03-10T22:40:37.000000+00:00 app[api]: Build started by user bris47degrees@gmail.com 2018-03-10T22:41:11.017941+00:00 app[api]: Deploy a7465293 by user bris47degrees@gmail.com 2018-03-10T22:41:11.017941+00:00 app[api]: Release v5 created by user bris47degrees@gmail.com 2018-03-10T22:40:37.000000+00:00 app[api]: Build succeeded 2018-03-10T22:41:11.805609+00:00 heroku[web.1]: State changed from crashed to starting 2018-03-10T22:41:14.238089+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/bristech_server.jar` 2018-03-10T22:41:15.655343+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them. 2018-03-10T22:41:15.656220+00:00 app[web.1]: Error: Unable to access jarfile build/libs/bristech_server.jar 2018-03-10T22:41:15.712848+00:00 heroku[web.1]: State changed from starting to crashed 2018-03-10T22:41:15.693130+00:00 heroku[web.1]: Process exited with status 1 2018-03-10T22:42:07.343849+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bristech-server.herokuapp.com request_id=807880ea-219e-425b-88dc-0265c5800c3b fwd="77.101.215.27" dyno= connect= service= status=503 bytes= protocol=h ttps 2018-03-10T22:42:07.948730+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bristech-server.herokuapp.com request_id=2928b2e5-6133-454b-ba6a-5809755f0329 fwd="77.101.215.27" dyno= connect= service= status=503 bytes= protocol=https 2018-03-10T22:42:11.097608+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/users/1" host=bristech-server.herokuapp.com request_id=d158abb8-e7b3-4dfd-a889-8cf575eec7c0 fwd="77.101.215.27" dyno= connect= service= status=503 bytes= pro tocol=https 2018-03-10T22:42:11.379526+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bristech-server.herokuapp.com request_id=8e403565-3112-4a5a-8329-70883b0eb68a fwd="77.101.215.27" dyno= connect= service= status=503 bytes= protocol=https 2018-03-10T22:42:27.000000+00:00 app[api]: Build started by user bris47degrees@gmail.com 2018-03-10T22:43:02.996084+00:00 app[api]: Deploy f76796c1 by user bris47degrees@gmail.com 2018-03-10T22:43:02.996084+00:00 app[api]: Release v6 created by user bris47degrees@gmail.com 2018-03-10T22:42:27.000000+00:00 app[api]: Build succeeded 2018-03-10T22:43:03.470870+00:00 heroku[web.1]: State changed from crashed to starting 2018-03-10T22:43:05.898870+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/bristech.jar` 2018-03-10T22:43:07.244601+00:00 heroku[web.1]: Process exited with status 1 2018-03-10T22:43:07.194950+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them. 2018-03-10T22:43:07.195870+00:00 app[web.1]: Error: Unable to access jarfile build/libs/bristech.jar 2018-03-10T22:43:07.258778+00:00 heroku[web.1]: State changed from starting to crashed 
web: java -jar build/libs/bristech.jar 
group 'com.bristech' version '1.0-SNAPSHOT' apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'org.springframework.boot' buildscript < repositories < mavenCentral() >dependencies < classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE") >> repositories < mavenCentral() maven < url "https://repository.jboss.org/nexus/content/repositories/releases" >maven < url 'https://repo.spring.io/libs-snapshot' >> jar < baseName = 'bristech' >task stage < dependsOn build >sourceCompatibility = 1.8 targetCompatibility = 1.8 dependencies < //Spring web, database and security implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("mysql:mysql-connector-java:5.1.6") implementation 'com.google.firebase:firebase-admin:5.9.0' //logging implementation("org.apache.logging.log4j:log4j-api:2.10.0") implementation("org.apache.logging.log4j:log4j-core:2.10.0") testCompile group: 'junit', name: 'junit', version: '4.12' >

I suspect that the error has to to with the jar file. I’ve tried running it without a Procfile too, however it still doesn’t work.

Читайте также:  Java visitor pattern hackerrank

I think by running locally, you mean running from target folder. copy the jar somewhere else and run, I suspect this wont work because the jar does not have required dependencies (hence class not found exception). If you see this is the issue, try creating fat jar using spring boot plugin.

@bestwishes by running locally I mean that I can build it as it is with IntelliJ, however when I push it to Heroku, it doesn’t build

Источник

Оцените статью