When I build my jar, I get ClassNotFoundException for AutoConfigurationReportLoggingInitializer.
This class is not in Spring libraries built by Gradle and also the class is not necessary for running in IDE. Is it possible to disable searching for this class? Or do you have some other solution?
EXCEPTION:
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:438)
... 10 more
build.gradle:
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
Try adding the spring-boot-starter dependency which includes spring-boot-starter-logging which has the class you are missing
Related
When I start the spring boot application built on gradle, it gives me the following error.
build.gradle
`plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'war'
}
group = 'gov.rta'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/javax.validation/validation-api
compile group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}`
When I start the application it gives me following error:
Caused by: java.lang.NoClassDefFoundError: javax.validation.ParameterNameProvider
at org.springframework.boot.autoconfigure.validation.ValidatorAdapter.create(ValidatorAdapter.java:134) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.autoconfigure.validation.ValidatorAdapter.getExistingOrCreate(ValidatorAdapter.java:117) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.autoconfigure.validation.ValidatorAdapter.get(ValidatorAdapter.java:109) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration.mvcValidator(WebMvcAutoConfiguration.java:468) ~[spring-boot-autoconfigure-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90) ~[na:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) ~[na:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:508) ~[na:1.8.0]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
... 98 common frames omitted
I have a project for which I use gradle, and I wanted to use the logger slf4j provides.
Running in Android Studio produces the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.mypkg.Main.<clinit>(Main.java:9)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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
My build.gradle for the project:
task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.0'
}
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'application'
jar {
manifest {
attributes 'Main-Class': "Main"
}
}
shadowJar {
mergeServiceFiles('META-INF/spring.*')
}
mainClassName = 'com.mypkg.Main'
dependencies {
compile 'com.squareup:otto:1.3.5'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.4'
compile 'com.squareup.okhttp:okhttp:2.7.4'
compile 'com.squareup.okhttp:okhttp-ws:2.7.4'
compile 'com.parse.bolts:bolts-android:1.2.1'
compile 'org.json:json:20140107'
compile 'org.bouncycastle:bcprov-jdk15on:1.52'
compile 'commons-codec:commons-codec:1.10'
compile 'org.scream3r:jssc:2.8.0'
compile 'ch.qos.logback:logback-classic:1.1.3'
compile 'ch.qos.logback:logback-core:1.1.3'
compile 'org.json:json:20140107'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
compile group: 'org.springframework.shell', name: 'spring-shell', version: '1.2.0.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support', version: '4.2.4.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '4.2.4.RELEASE'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
If I build this project with gradle, the shadow plugin generates a fat jar, which runs from the console nicely, it includes the logger, but from the IDE I'm having difficulties finding the LoggerFactory. I read here that I should add the logger to the classpath but since I don't explicitly include a jar, rather than marking it as a dependency, I'm not sure how this would be possible.
Please advise.
Cheers!
The classpath is out of sync, few options here
Refresh the project in IntelliJ (the older versions of IntelliJ are not ideal with gradle integration)
add apply plugin: 'idea' to your build.gradle and then run gradle idea to regenerate .iml .ipr .iws files in your project and pick up dependencies from gradle.(Not ideal! see why)
Download latest version of IntelliJ and redo option 1
Edit: Thanks #CrazyCoder for this hint.
I have Spring Boot application with slf4j logging.
Gradle:
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
compile group: 'com.google.guava', name: 'guava', version: '17.0'
// Spring
compile 'org.springframework.boot:spring-boot-starter-web:1.5.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '1.5.1.RELEASE'
// Spring Security
compile 'org.springframework.boot:spring-boot-starter-security'
// Template engine
compile 'org.springframework.boot:spring-boot-starter-thymeleaf:1.5.1.RELEASE'
compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.2.RELEASE'
compile group: 'org.thymeleaf', name: 'thymeleaf-spring5', version: '3.0.3.M1'
// DB and ORM
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.5.1.RELEASE'
compile 'org.apache.derby:derby:10.13.1.1'
// Form validation
compile 'org.hibernate:hibernate-validator:5.2.2.Final'
compile 'javax.el:el-api:2.2'
// SNMP
compile 'org.snmp4j:snmp4j:1.10.1'
compile 'org.snmp4j:snmp4j-agent:1.2'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Class:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
.....
#SpringBootApplication
public class MyApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(MyApplication.class);
public static void main(String[] args) {
SpringApplication.run(new Class<?>[] {MyApplication.class}, args);
.....
It worked before. Now I have exception where I create Logger. I didn't change anything, only tried to build project again. Maybe Spring Boot version was changed, I don't know.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at by.virkom.MyApplication.<clinit>(MyApplication.java:18)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
I tried to exclude spring-boot-starter-logging and connect
spring-boot-starter-log4j but it not worked for me. Then ClassNotFoundException with Log4j. How can I fix it?
P.S.: When I commented creating logger, I have another exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at by.virkom.MyApplication.main(MyApplication.java:22)
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:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
add this to your gradle file:
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.5'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.5'
You have to add an implementation of slf4j Logger like logback
Add the following to your gradle build
compile 'ch.qos.logback:logback-classic:1.1.7'
You have two options:
If your app is a webapp, add spring-boot-starter-web as a dependency and all logging dependencies will be added.
If your app is no webapp, add spring-boot-starter-logging as a dependency.
Source: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
I have developed a batch processing program using Spring Boot 1.4.2, which takes a long time (about 5 hours) to execute. After about 5 hours passes since the program launches, it finishes execution with an error message below:
20:49:01.324 ERROR o.s.boot.SpringApplication - Application startup failed
java.lang.NoClassDefFoundError: org/springframework/util/StopWatch$TaskInfo
at org.springframework.util.StopWatch.stop(StopWatch.java:146)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at com.example.Main.main(Main.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.ClassNotFoundException: org.springframework.util.StopWatch$TaskInfo
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 common frames omitted
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringBootExceptionHandler
at org.springframework.boot.SpringApplication.getSpringBootExceptionHandler(SpringApplication.java:903)
at org.springframework.boot.SpringApplication.registerLoggedException(SpringApplication.java:850)
at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:840)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:816)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at jp.co.cyberagent.leeds.article_batches.ArticleBatchesApplication.main(ArticleBatchesApplication.java:25)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringBootExceptionHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more
It seems that I am missing some dependencies on Spring Framework, but I don't know what I really need.
Here's my build.gradle.
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'article-batches'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven {
url "https://maven.ca-tools.org/content/groups/public/"
}
}
dependencies {
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1')
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.40'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
compile group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.1'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I solved the problem by myself. My main process was written in CommandLineRunner#run method, but it is wrong way to write main process in run method as this comment says in another question.
I followed the comment and wrote my main process like below, then the problem has gone away.
#SpringBootApplication
public class Main {
public static void main(String[] args) {
final ConfigurableApplicationContext context = SpringApplication.run(Main.class, args);
final AppBean app = context.getBean(AppBean.class);
app.run(args);
}
}
I'm trying to add the lib from esotericsoftware "Kryo" to my libGDX project on the Desktop and Android module. I'm using Intellij.
What I tried:
Adding the kryo-3.0 folder to the External Libraries
Adding the dependencies in build.gradle to all modules
compile "com.esotericsoftware:kryo:3.0.3"
Run the Gradle
Sync Project.
What I got after compile the Desktop module:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: org/objenesis/strategy/InstantiatorStrategy
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131)
Caused by: java.lang.NoClassDefFoundError: org/objenesis/strategy/InstantiatorStrategy
at com.projectbeta.deepdarkness.screens.MenuScreen.show(MenuScreen.java:18)
at com.badlogic.gdx.Game.setScreen(Game.java:61)
at com.projectbeta.deepdarkness.DeepDarkness.create(DeepDarkness.java:16)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
Caused by: java.lang.ClassNotFoundException: org.objenesis.strategy.InstantiatorStrategy
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)
... 5 more
Just tested and it works, paste that into root gradle.build of your project (not in some of the module specific) and resync.
project(":core") {
apply plugin: "java"
dependencies {
......
compile group: 'com.esotericsoftware', name: 'kryo', version: '3.0.3'
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
.......
compile group: 'com.esotericsoftware', name: 'kryo', version: '3.0.3'
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
......
compile group: 'com.esotericsoftware', name: 'kryo', version: '3.0.3'
}
}