I am upgrading my grails 2.5.x application to grails 4.0.8
After adding everything and all dependencies i am getting this error.
java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
I found various similar post on the same error but none seems to work. This error seems to be very user specific.
My stacktrace looks like this->
C:\Java-11.0.8_10-winx64\bin\java.exe -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Djline.WindowsTerminal.directConsole=false -Dfile.encoding=UTF-8 #C:\Users\username\AppData\Local\Temp\idea_arg_file229552621 org.grails.cli.GrailsCli run-app --plain-output
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/idnsuv/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.14/f0a005fb21e7bd9b7ebf04cd2ecda0fc8f3be59d/groovy-2.5.14.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
|Running application...
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/idnsuv/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.14/f0a005fb21e7bd9b7ebf04cd2ecda0fc8f3be59d/groovy-2.5.14.jar) to method java.lang.reflect.AnnotatedElement.lambda$getDeclaredAnnotationsByType$0(java.lang.annotation.Annotation,java.lang.annotation.Annotation)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
WARNING: The hasOne property in class [com.ideas.cma.gft.RateSourceGftServerDetails] should have an initial expression of type Map or Class.
WARNING: The hasOne property in class [com.ideas.cma.gft.RateSourceGftServerDetails] should have an initial expression of type Map or Class.
WARNING: The hasOne property in class [com.ideas.cma.gft.RateSourceGftServerDetails] should have an initial expression of type Map or Class.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/idnsuv/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.14/f0a005fb21e7bd9b7ebf04cd2ecda0fc8f3be59d/groovy-2.5.14.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-03-05 09:49:39.795 ERROR --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplicationPostProcessor' defined in com.ideas.cma.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is org.grails.core.exceptions.GrailsRuntimeException: Error instantiated artefact class [class com.ideas.cma.excelExport.myTasks.MyTeamTaskExcelExportService] of type [class org.grails.core.DefaultGrailsServiceClass]: InvocationTargetException
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:118)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
at grails.boot.GrailsApp.run(GrailsApp.groovy:485)
at grails.boot.GrailsApp.run(GrailsApp.groovy:472)
at com.ideas.cma.Application.main(Application.groovy:11)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is org.grails.core.exceptions.GrailsRuntimeException: Error instantiated artefact class [class com.ideas.cma.excelExport.myTasks.MyTeamTaskExcelExportService] of type [class org.grails.core.DefaultGrailsServiceClass]: InvocationTargetException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
... 25 common frames omitted
Caused by: org.grails.core.exceptions.GrailsRuntimeException: Error instantiated artefact class [class com.ideas.cma.excelExport.myTasks.MyTeamTaskExcelExportService] of type [class org.grails.core.DefaultGrailsServiceClass]: InvocationTargetException
at grails.core.ArtefactHandlerAdapter.newArtefactClass(ArtefactHandlerAdapter.java:170)
at grails.core.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:812)
at grails.core.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:504)
at grails.core.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:775)
at grails.boot.config.GrailsApplicationPostProcessor.performGrailsInitializationSequence(GrailsApplicationPostProcessor.groovy:112)
at grails.boot.config.GrailsApplicationPostProcessor.initializeGrailsApplication(GrailsApplicationPostProcessor.groovy:94)
at grails.boot.config.GrailsApplicationPostProcessor.setApplicationContext(GrailsApplicationPostProcessor.groovy:231)
at grails.boot.config.GrailsApplicationPostProcessor.<init>(GrailsApplicationPostProcessor.groovy:78)
at grails.boot.config.GrailsAutoConfiguration.grailsApplicationPostProcessor(GrailsAutoConfiguration.groovy:68)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 26 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at grails.core.ArtefactHandlerAdapter.newArtefactClass(ArtefactHandlerAdapter.java:161)
... 39 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3191)
at java.base/java.lang.Class.getMethods(Class.java:1904)
at java.desktop/com.sun.beans.introspect.MethodInfo.get(MethodInfo.java:70)
at java.desktop/com.sun.beans.introspect.ClassInfo.getMethods(ClassInfo.java:71)
at java.desktop/java.beans.Introspector.getTargetMethodInfo(Introspector.java:1046)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:462)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:205)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:293)
at java.desktop/java.beans.Introspector.<init>(Introspector.java:443)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:205)
at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:3356)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3354)
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3331)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:287)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:329)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:272)
at org.grails.datastore.mapping.reflect.ClassPropertyFetcher.getStaticPropertyValue(ClassPropertyFetcher.java:176)
at org.grails.core.AbstractGrailsClass.getStaticPropertyValue(AbstractGrailsClass.java:239)
at org.grails.core.DefaultGrailsServiceClass.<init>(DefaultGrailsServiceClass.java:34)
... 44 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:144)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 66 common frames omitted
Using java 11 with grails 4.0.8 (grails 4 uses gradle build) in IntelliJ idea.
Running in java 8 doesn't make a difference.
Using pathingJar in gradle as such huge dependencies give the file path/ extention too long error in windows 10
build.gradle(minified)--
buildscript {
repositories {
maven { url "http://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.0"
classpath "org.grails.plugins:hibernate5:7.0.4"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.2.4"
}
}
version "0.1"
group "com.domain.projectname"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"com.github.erdi.webdriver-binaries"
apply plugin:"com.bertramlabs.asset-pipeline"
apply plugin:"org.grails.grails-gsp"
repositories {
mavenCentral()
maven { url "http://repo.grails.org/grails/core" }
//for external-config
maven { url "https://oss.jfrog.org/repo/" }
maven { url "https://repo.grails.org/grails/plugins" }
flatDir {
dirs 'lib'
}
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core:4.0.8"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core"
compile "org.grails.plugins:gsp"
compileOnly "io.micronaut:micronaut-inject-groovy"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2:1.4.199"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "javax.xml.bind:jaxb-api:2.3.1"
runtime "com.bertramlabs.plugins:asset-pipeline-grails"
testCompile "io.micronaut:micronaut-inject-groovy"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.mockito:mockito-core"
testCompile "org.grails:grails-web-testing-support"
testCompile "org.grails.plugins:geb"
testCompile "org.seleniumhq.selenium:selenium-remote-driver"
testCompile "org.seleniumhq.selenium:selenium-api:3.14.0"
testCompile "org.seleniumhq.selenium:selenium-support:3.14.0"
testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:3.14.0"
testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:3.14.0"
// User added
compile 'org.grails.plugins:external-config:2.0.0'
//Below are the dependencies which are situated in /lib folder as .jar
compile name: 'activation'
compile name: 'axis'
compile name: 'cma-common'
compile name: 'commons-collections4-4.1'
compile name: 'commons-discovery-0.2'
compile name: 'commons-logging-1.0.4'
compile name: 'concurrent'
compile name: 'CSVUpload'
compile name: 'DynamicJasper-3.0.4'
compile name: 'hibernate-entitymanager'
compile name: 'hibernate-search'
compile name: 'hibernate-validator'
compile name: 'ideas-intf-integration'
compile name: 'iText-2.1.4'
compile name: 'jasperreports-3.1.4'
compile name: 'jaxb1-impl'
compile name: 'jaxb-impl'
compile name: 'jaxb-xjc'
compile name: 'jaxrpc'
compile name: 'jbossall-ideas-client'
compile name: 'jboss-aop-jdk50'
compile name: 'jboss-jaxws'
compile name: 'jboss-messaging-client'
compile name: 'jboss-remoting'
compile name: 'jboss-saaj'
compile name: 'jboss-serialization'
compile name: 'jbossws-client'
compile name: 'jbossws-common'
compile name: 'jbossws-spi'
compile name: 'jboss-xml-binding'
compile name: 'jms'
compile name: 'jnp-client'
compile name: 'jsr173_1.0_api'
compile name: 'lucene-core'
compile name: 'mail'
compile name: 'mysql-connector-java-5.1.20'
compile name: 'policy'
compile name: 'saaj'
compile name: 'sfdcws'
compile name: 'sqljdbc4-1'
compile name: 'trove'
compile name: 'ooxml-schemas-1.3'
compile name: 'poi-3.17'
compile name: 'poi-ooxml-3.17'
compile name: 'poi-ooxml-schemas-3.17'
compile name: 'wsdl4j-1.5.1'
compile name: 'xercesImpl'
compile name: 'xmlbeans-3.1.0'
compile name: 'xpp3_min-1.1.4c'
compile name: 'xstream-1.3.1'
runtimeOnly group: 'org.grails.plugins', name: 'jquery', version: '1.11.1'
runtimeOnly group: 'org.grails.plugins', name: 'resources', version: '1.2.14'
implementation group: 'org.grails.plugins', name: 'bubbling', version: '1.5.1'
implementation group: 'org.grails.plugins', name: 'calendar', version: '1.2.1'
implementation group: 'org.grails.plugins', name: 'code-coverage', version: '1.1.6'
implementation group: 'org.grails.plugins', name: 'webflow', version: '2.1.0'
compile "org.grails.plugins:shiro:1.2.1"
implementation group: 'org.grails.plugins', name: 'yui', version: '2.8.2.1'
implementation group: 'org.apache.tomcat', name: 'tomcat', version: '7.0.70', ext: 'pom'
compile "org.grails.plugins:calendar:1.2.1"
implementation group: 'org.grails.plugins', name: 'ckeditor', version: '4.5.9.0'
implementation group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
provided "opensymphony:quartz-all:1.6.3"
runtime "commons-io:commons-io:2.4"
runtime "org.springframework:spring-context-support:3.1.0.RELEASE"
runtime "org.springframework:spring-jms:3.1.0.RELEASE"
runtime "org.jboss.logging:jboss-logging:3.2.1.Final"
runtime "commons-dbcp:commons-dbcp:1.4"
compile 'org.springframework:spring-jms:5.1.20.RELEASE'
}
bootRun {
ignoreExitValue true
jvmArgs(
'-Dspring.output.ansi.enabled=always',
'-noverify',
'-XX:TieredStopAtLevel=1',
'-Xmx1024m')
sourceResources sourceSets.main
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
grails{
pathingJar = true
}
P.S. -> getting similar errors for other dependencies too -> too a "grails dependency-report" and got this. Dont know how to resolve it.(Below is just a path. Thw hole report is too long)
+--- myproject-common (n) //A required jar from my another project
+--- commons-collections4-4.1 (n)
+--- commons-discovery-0.2 (n)
+--- commons-logging-1.0.4 (n)
+--- concurrent (n)
+--- CSVUpload (n)
+--- DynamicJasper-3.0.4 (n)
+--- hibernate-entitymanager (n)
+--- hibernate-search (n)
+--- hibernate-validator (n)
+--- myproject-intf-integration (n) //A required jar from my another project
+--- iText-2.1.4 (n)
+--- jasperreports-3.1.4 (n)
+--- jaxb1-impl (n)
+--- jaxb-api (n)
+--- jaxb-impl (n)
+--- jaxb-xjc (n)
+--- jaxrpc (n)
+--- jbossall-ideas-client (n)
+--- jboss-aop-jdk50 (n)
+--- jboss-jaxws (n)
+--- jboss-messaging-client (n)
+--- jboss-remoting (n)
+--- jboss-saaj (n)
+--- jboss-serialization (n)
+--- jbossws-client (n)
+--- jbossws-common (n)
+--- jbossws-spi (n)
+--- jboss-xml-binding (n)
+--- jms (n)
+--- jnp-client (n)
+--- jsr173_1.0_api (n)
+--- lucene-core (n)
+--- mail (n)
+--- mysql-connector-java-5.1.20 (n)
+--- policy (n)
+--- saaj (n)
+--- sfdcws (n)
+--- sqljdbc4-1 (n)
+--- trove (n)
+--- wsdl4j-1.5.1 (n)
+--- xercesImpl (n)
+--- xmlbeans-3.1.0 (n)
+--- xpp3_min-1.1.4c (n)
+--- xstream-1.3.1 (n)
+--- org.grails.plugins:quartz:2.0.13 (n)
+--- commons-io:commons-io:2.8.0 (n)
+--- org.springframework:spring-context-support:3.2.18.RELEASE (n)
+--- org.apache.poi:poi-ooxml-schemas:4.1.2 (n)
+--- org.apache.poi:poi:4.1.2 (n)
+--- org.apache.poi:poi-ooxml:4.1.2 (n)
+--- org.quartz-scheduler:quartz:1.7.2 (n)
\--- org.grails.plugins:jms:2.0.0.RC2 (n)
I have also tried deleting .m2, .grails, .gradle, grails clean and basically everything related to resetting the project
From the error, it looks like your application is not able to find org.apache.poi.ss.usermodel.Workbook. It may be due to multiple reasons, such as:
The Apache poi JAR is not present in the classpath. So, you would need to add the corresponding dependencies.
It may also happen when you have different version of multiple poi libraries, which I think are not compatible with each other. In this case, you need to make sure that every poi dependency is pointing to the same version.
Lastly, you may want to check that the class with same package is present in the respective version of library. The easiest way to check if you are using JetBrains IntelliJ Idea is to navigate to class.
Related
I have a multi-module setup for a Java project with following structure.
mainApp
|--> core-module
| |--> src
| |--> build.gradle
|--> implementation group: 'org.apache.axis2', name: 'axis2-kernel', version: '1.7.8'
|--> implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.13'
|--> implementation files('libs/some_local.jar')
|--> compile project(":lib-module")
|--> compile project(":lib-another-module")
|--> ...
|
|--> lib-module
| |--> src
| |--> build.gradle
|--> implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
|--> implementation files('libs/another_local.jar')
|--> ...
|--> lib-another-module
| |--> src
| |--> build.gradle
|--> implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|--> implementation files('libs/another_local.jar')
|--> ...
|
|--> settings.gradle
|--> build.gradle
|--> gradle.properties
In mainApp/build.gradle file I have a 'mentioned' sub-modules as
sourceSets {
main {
java {
srcDirs project('core-module').file("src")
srcDirs project('lib-module').file("src")
srcDirs project('lib-another-module').file("src")
}
}
}
If I build individual sub-module it get compiled successfully but when I run ./gradlew compileJava at root , it fails with classNotFoundExceptions from the jars which I've already mentioned in sub-modules
> Task :core-module:compileJava
//successful
> Task :lib-module:compileJava
//successful
> Task :lib-another-module:compileJava
//successful
> Task :compileJava
/.../core-module/src/java/../OAuthUtils.java:12: error: package org.apache.http does not exist
import org.apache.http.Header;
...
//FAILED!
Here ./gradlew core-module:compileJava works perfectly but compilation fails when invoked from root.
How shall I deal with it?
Is it because of some local jars referred from file-system?
EDIT
I found that the compilation of root sourceSets{} which is pointing to child sub-module is failing and individual sub-module compilation is successful.
But, I need this sourceSets{} for creating one monolithic jar of all sub-module
Note:- I'm not creating fatJar or shadedJar here, But I need to include all packages from all sub-modules without dependency jars.
This how I'm successfully able to create the one monolithic jar from all sub-module
jar {
dependsOn compileJava
manifest {
def userName = System.properties['user.name']
def javaVersion = JavaVersion.current()
attributes 'Manifest-Version' : "1.0"
attributes 'Built-By' : userName
attributes 'Created-By' : "Java Version: " + javaVersion
}
destinationDir(file("$buildDir/image"))
baseName(jarName)
from project('core-module').sourceSets.main.output.classesDirs
from project('lib-module').sourceSets.main.output.classesDirs
from project('lib-another-module').sourceSets.main.output.classesDirs
}
Hi I'm new to gradle and java and IJ idea. I am trying to build some java project using gradle. When I run command:
C:\Users\xxx\IdeaProjects\example2>gradle build
The build fails.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not resolve org.testng:testng:6.14.3.
Required by:
project :
> Could not resolve org.testng:testng:6.14.3.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/testng/testng/6.14.3/testng-6.14.3.pom'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/testng/testng/6.14.3/testng-6.14.3.pom'.
> Received fatal alert: access_denied
Folder IdeaProjects/example2 has fully accesible for all users. When I run the command with --stacktrace option, the last "caused by" is:
... 106 more
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: access_denied
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
Could it be problem with SSL certificate? I'm using proxy to connect to the web.
This is build.gradle file I'm using
plugins {
id 'java'
id 'idea'
}
group 'jetbrains'
version '1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
//testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.testng', name: 'testng', version: '6.14.3'
// https://mvnrepository.com/artifact/io.rest-assured/rest-assured
//compile group: 'io.rest-assured', name: 'rest-assured', version: '3.1.0'
//testCompile group: 'io.rest-assured', name: 'rest-assured', version: '3.1.0'
}
Problem solved, thanks to stackoverflow.com/a/22666646/2987755. Following variables/properties must be set in gradle.properties file.
systemProp.http.proxyHost=$proxy
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=$proxy
systemProp.https.proxyPort=8080
I'm trying to integrate a Log4J2 Appender to RabbitMQ in an already working and logging java application.
The application is build as a gradle project. Before the integration of spring-rabbit, the build.gradle file looked like this:
group 'Name'
version '1.18.7'
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
[...]
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7'
[...]
}
jar {
manifest {
attributes 'Main-Class': 'the.main.Clazz'
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: '2.0.2'
}
}
The log4j2.xml file, positioned in the src/resources folder, contains this (before rabbitMQ):
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="15">
<Appenders>
<Console name="STDOUT">
<PatternLayout>
<Pattern>%d [%highlight{%-6p}{STYLE=DEFAULT, noConsoleNoAnsi=true}] %C{1}.%M(%F:%L) - %m%n%throwable</Pattern>
</PatternLayout>
</Console>
<RandomAccessFile name="ASYNC_FILE" fileName="logs/app.log" immediateFlush="false" append="true">
<PatternLayout>
<Pattern>%d [%-6p] %C{1}.%M(%F:%L) - %m%n%throwable</Pattern>
</PatternLayout>
</RandomAccessFile>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="STDOUT"/>
</Root>
<Logger name="my.package" level="info" additivity="false">
<AppenderRef ref="ASYNC_FILE"/>
</Logger>
</Loggers>
</Configuration>
The application runs nicely, as well as from the IDE and the JAR, built with the shadowJar plugin.
Now, the mystery begins. Simply by adding the spring-rabbit dependency...
compile group: 'org.springframework.amqp', name: 'spring-rabbit', version: '2.0.2.RELEASE'
...logging starts to behave very strange. Started from the IDE, everything works still nice. Adding the following appender to the log4j2.xml works fine:
<RabbitMQ name="RABBIT_MQ"
host="my.host.name" port="5672" user="logger" password="logger" virtualHost="loggerhost"
exchange="logs" exchangeType="fanout" declareExchange="false"
applicationId="app-xyz" routingKeyPattern="%X{applicationId}.%c.%p"
contentType="text/plain" contentEncoding="UTF-8" generateId="true" deliveryMode="NON_PERSISTENT"
charset="UTF-8"
senderPoolSize="3" maxSenderRetries="5">
<PatternLayout>
<Pattern>%d [%-6p] %C{1}.%M(%F:%L) - %m%n%throwable</Pattern>
</PatternLayout>
</RabbitMQ>
I see the log messages delivered via the RabbitMQ server.
But when I build and run the JAR file built with :shadowJar, logging stops working. On STDOUT, I see the following:
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
When I start the application JAR with the -Dlog4j2.debug option I see a lot of messages, and some seem to say, that the configuration cannot be loaded (which is still at the same place). Here an excerpt:
DEBUG StatusLogger Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory#2a33fae0
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.
I even used the -Dlog4j.configurationFile option, pointing directly to the XML in the file system, but the result stays the same.
Again, starting the application from the IDE and not via java -jar ... works fine. It seems to me as if the spring-rabbitmq dependency brings some extra log4j stuff that interferes with my configuration. I'm totally fishing in murky waters.
So, after a lot of research I can answer my question with the following.
It is not enough to simply add the Spring-Rabbit-MQ org.springframework.amqp:spring-rabbit dependency to let the Log4J2 configuration fail. It's the combination with another dependency, that is not listed in my example: com.fasterxml.jackson.core:jackson-databind.
To sum it up. This does not work:
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.3'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7'
compile group: 'org.springframework.amqp', name: 'spring-rabbit', version: '2.0.2.RELEASE'
But this works (without Spring):
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.3'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7'
And this works (without Jackson):
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7'
compile group: 'org.springframework.amqp', name: 'spring-rabbit', version: '2.0.2.RELEASE'
So the combination of Jackson and Spring breaks Log4J2. Interestingly, without Jackson, my program works as well, even if Jackson is under heavy use. Let's have a look on that, what gradle dependecies has to say:
compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- org.apache.logging.log4j:log4j-api:2.10.0
+--- org.apache.logging.log4j:log4j-core:2.10.0
| \--- org.apache.logging.log4j:log4j-api:2.10.0
+--- com.lmax:disruptor:3.3.7
\--- org.springframework.amqp:spring-rabbit:2.0.2.RELEASE
+--- org.springframework.amqp:spring-amqp:2.0.2.RELEASE
| \--- org.springframework:spring-core:5.0.3.RELEASE
| \--- org.springframework:spring-jcl:5.0.3.RELEASE
+--- com.rabbitmq:amqp-client:5.1.2
| \--- org.slf4j:slf4j-api:1.7.25 -> 1.8.0-alpha2
+--- com.rabbitmq:http-client:1.3.1.RELEASE
| +--- org.apache.httpcomponents:httpclient:4.5.3
| | +--- org.apache.httpcomponents:httpcore:4.4.6
| | +--- commons-logging:commons-logging:1.2
| | \--- commons-codec:commons-codec:1.9 -> 1.11
| \--- com.fasterxml.jackson.core:jackson-databind:2.9.2
| +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| \--- com.fasterxml.jackson.core:jackson-core:2.9.2
+--- org.springframework:spring-context:5.0.3.RELEASE
| +--- org.springframework:spring-aop:5.0.3.RELEASE
| | +--- org.springframework:spring-beans:5.0.3.RELEASE
| | | \--- org.springframework:spring-core:5.0.3.RELEASE (*)
| | \--- org.springframework:spring-core:5.0.3.RELEASE (*)
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| +--- org.springframework:spring-core:5.0.3.RELEASE (*)
| \--- org.springframework:spring-expression:5.0.3.RELEASE
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-messaging:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-tx:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-web:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
\--- org.springframework.retry:spring-retry:1.2.1.RELEASE
\--- org.springframework:spring-core:4.3.9.RELEASE -> 5.0.3.RELEASE (*)
Oh, wait, there's also a Jackson within the Spring AMQP. Well, that solves the riddle, why I can still use Jackson after removing the dependency. But this is very intransparent to me and depends on the Spring AMQP package to deliver a core dependency for me. So what I finally did is this, and it seems to work:
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.3'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7' version: '2.12.0'
compile (group: 'org.springframework.amqp', name: 'spring-rabbit', version: '2.0.2.RELEASE') {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
}
The dependency tree looks like the following now:
compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- com.fasterxml.jackson.core:jackson-databind:2.9.3
| +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| \--- com.fasterxml.jackson.core:jackson-core:2.9.3
+--- org.apache.logging.log4j:log4j-api:2.10.0
+--- org.apache.logging.log4j:log4j-core:2.10.0
| \--- org.apache.logging.log4j:log4j-api:2.10.0
+--- com.lmax:disruptor:3.3.7
\--- org.springframework.amqp:spring-rabbit:2.0.2.RELEASE
+--- org.springframework.amqp:spring-amqp:2.0.2.RELEASE
| \--- org.springframework:spring-core:5.0.3.RELEASE
| \--- org.springframework:spring-jcl:5.0.3.RELEASE
+--- com.rabbitmq:amqp-client:5.1.2
| \--- org.slf4j:slf4j-api:1.7.25 -> 1.8.0-alpha2
+--- com.rabbitmq:http-client:1.3.1.RELEASE
| \--- org.apache.httpcomponents:httpclient:4.5.3
| +--- org.apache.httpcomponents:httpcore:4.4.6
| +--- commons-logging:commons-logging:1.2
| \--- commons-codec:commons-codec:1.9 -> 1.11
+--- org.springframework:spring-context:5.0.3.RELEASE
| +--- org.springframework:spring-aop:5.0.3.RELEASE
| | +--- org.springframework:spring-beans:5.0.3.RELEASE
| | | \--- org.springframework:spring-core:5.0.3.RELEASE (*)
| | \--- org.springframework:spring-core:5.0.3.RELEASE (*)
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| +--- org.springframework:spring-core:5.0.3.RELEASE (*)
| \--- org.springframework:spring-expression:5.0.3.RELEASE
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-messaging:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-tx:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-web:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
\--- org.springframework.retry:spring-retry:1.2.1.RELEASE
\--- org.springframework:spring-core:4.3.9.RELEASE -> 5.0.3.RELEASE (*)
I must admit that I not fully understand why the combination of two Jackson dependencies brings the Log4J2 configuration down, but now it works with this strategy:
Declare Jackson dependency explicitly (make transparent, that the application uses Jackson)
Exclude Jackson from Spring dependency
And what I really don't get: Why do all combinations work from within the IDE, but later fail when running the JAR?
This is a known issue with log4j, reported over 3 years ago. It comes up when you use the shadowjar plugin. See shadowjar issue here.
You can read both tickets to get a better understanding, but if you're looking for a point-and-click solution, just use this gradle plugin:
plugins {
id "com.github.johnrengelman.shadow" version "2.0.2"
id "de.sebastianboegl.shadow.transformer.log4j" version "2.2.0"
}
... or revert to log4j 2.0.2.
I'm writing a Java program that runs from the command line and uses a library that I wrote to parse command line arguments. Since my library isn't on maven repository, I'm using flatDir in gradle to grab the jar from a directory local/ containing the jar file. Here is my build.gradle:
apply plugin: 'java-library'
repositories {
jcenter()
mavenCentral()
flatDir(dirs: 'local')
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:21.0'
testImplementation 'junit:junit:4.12'
// https://mvnrepository.com/artifact/javax.mail/mail
compile group: 'javax.mail', name: 'mail', version: '1.4.1'
// https://mvnrepository.com/artifact/org.mongodb/mongodb-driver
compile group: 'org.mongodb', name: 'mongodb-driver', version: '3.4.2'
// https://mvnrepository.com/artifact/org.jsoup/jsoup
compile group: 'org.jsoup', name: 'jsoup', version: '1.7.2'
// https://mvnrepository.com/artifact/log4j/log4j
compile group: 'log4j', name: 'log4j', version: '1.2.12'
// not in maven repository
compile 'JModule:JModule:1.3.1'
}
task copyToLib(type: Copy) {
from configurations.compile
into 'dependencies'
}
build.dependsOn(copyToLib)
My code runs fine in the eclipse IDE, and runs fine from the command line when I comment out all the references to JModule (my library) and run it with all the other libraries I'm using. However, when I run it with JModule as a dependency, it produces the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/jModule/def/CommandLogic
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.jModule.def.CommandLogic
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)
... 7 more
I've already tried removing references to the class com.JModule.commandLogic but this only produces the same error with other JModule classes. Just to be clear, I'm not yet exporting to a jar - I'm just running the main class from the command line using the "java" command. The jar is also in the eclipse folder "project and external dependencies" so I'm assuming this means it's in my classpath, since the other jars in there run fine in my program.
Any help would be appreciated, thanks
My team has our application's com.mysql.jdbc.Driver jar in the $JAVA_HOME/jre/lib/ext/ folder, but i'm trying to remove this dependency on the JDK to create a more repeatable build with Gradle.
I added the driver into my build.gradle, which you can see at the top of my dependencies:
dependencies {
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.+'
compile group: 'com.notnoop.apns', name: 'apns', version: '1.0.0.Beta6'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
compile group: 'com.google.code.gson', name: 'gson', version: '1.7.2'
compile group: 'net.sf.jazzy', name: 'jazzy', version: '0.5.2-rtext-1.4.1'
compile group: 'org.apache.lucene', name: 'com.springsource.org.apache.lucene.search.spell', version: '2.4.1'
compile group: 'com.rabbitmq', name: 'com.springsource.com.rabbitmq.client', version: '1.8.1'
compile group: 'com.sun.xml', name: 'com.springsource.com.sun.xml.bind', version: '2.2.0'
compile group: 'com.sun.xml.rpc', name: 'jaxrpc-impl', version: '1.1.3_01'
compile group: 'com.rabbitmq', name: 'amqp-client', version: '3.6.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.3.1'
compile fileTree(dir: 'local_lib', include: '*.jar')
}
After removing the jar from $JAVA_HOME/jre/lib/ext/ and putting it in gradle, I get this error in the Catalina logs after trying to access the database:
database.BaseDbao.getConnection - We could not create any connection.
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at database.BaseDbao.getConnection(BaseDbao.java:116)
at database.UserDbao.getAuthorizedResultBean(UserDbao.java:357)
at database.Dbao.getAuthorizedResultBean(Dbao.java:3635)
at AuthServlet.doPost(AuthServlet.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at servlets.filters.servletContextFilter.doFilter(servletContextFilter.java:11)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1130)
... 22 more
Dbao.getAuthorizationResultBean() Error - Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
LoginFailed for :suburbantest:because ::10.0.0.22
Any insight would be highly appreciated!
You define your datasource in Tomcat's configuration instead of putting it to your application configuration.
Tomcat has hierarchy of classloaders. You can read about it on its website, but to make the long story short there are three interesting classloaders: a JDK Classloader (Bootstrap), Tomcat classloader (System) and your app's classloader (In fact there are more, but lets make it simple).
When put the driver's jar into $JAVA_HOME/jre/lib/ext/, you add it to JDK classloader. When you add it to tomcat/lib, you add it to Tomcat classloader. And when you define it in your app's gradle, you add it to application classloader.
Since the datasource configuration in your case is located in Tomcat's config, it will search only the JDKs and Tomcat's classloader.
One solution is to define the datasource configuration within your app (why do you need it in Tomcat? Do you have multiple wars that use the same datasource? )