I have a problem..
I want to deploy my Spring Boot Gradle app to GC App Engine.
I use the command :
gradle appengineDeploy
It actually works but when i try to open the app in the browser it says :
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
So the app was deployed successfully but it has a problem to start..
java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cloudSqlDataSourceProperties' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/sql/GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Factory method 'cloudSqlDataSourceProperties' threw exception; nested exception is java.lang.IllegalStateException: Unable to set ApplicationName - SQLAdmin client already initialized.
at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart (ServletContainerInitializersStarter.java:68)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext (ServletContextHandler.java:330)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp (WebAppContext.java:1406)
at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.startWebapp (AppEngineWebAppContext.java:175)
at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1368)
at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:778)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:262)
at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:522)
at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doStart (AppEngineWebAppContext.java:120)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.createHandler (AppVersionHandlerMap.java:240)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.getHandler (AppVersionHandlerMap.java:178)
at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest (JettyServletEngineAdapter.java:120)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest (JavaRuntime.java:728)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest (JavaRuntime.java:691)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run (JavaRuntime.java:661)
at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run (JavaRuntime.java:853)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run (ThreadGroupPool.java:270)
at java.lang.Thread.run (Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cloudSqlDataSourceProperties' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/sql/GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Factory method 'cloudSqlDataSourceProperties' threw exception; nested exception is java.lang.IllegalStateException: Unable to set ApplicationName - SQLAdmin client already initialized.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate (ConstructorResolver.java:627)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod (ConstructorResolver.java:607)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod (AbstractAutowireCapableBeanFactory.java:1305)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java:1144)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java:849)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run (SpringApplication.java:316)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run (SpringBootServletInitializer.java:157)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext (SpringBootServletInitializer.java:137)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup (SpringBootServletInitializer.java:91)
at org.springframework.web.SpringServletContainerInitializer.onStartup (SpringServletContainerInitializer.java:171)
at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup (ContainerInitializer.java:140)
at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart (ServletContainerInitializersStarter.java:63)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Factory method 'cloudSqlDataSourceProperties' threw exception; nested exception is java.lang.IllegalStateException: Unable to set ApplicationName - SQLAdmin client already initialized.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate (ConstructorResolver.java:622)
Caused by: java.lang.IllegalStateException: Unable to set ApplicationName - SQLAdmin client already initialized.
at com.google.cloud.sql.core.CoreSocketFactory.setApplicationName (CoreSocketFactory.java:341)
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration.cloudSqlDataSourceProperties (GcpCloudSqlAutoConfiguration.java:209)
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$bb6c42e.CGLIB$cloudSqlDataSourceProperties$0 (<generated>)
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$bb6c42e$$FastClassBySpringCGLIB$$a426c72d.invoke (<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper (MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept (ConfigurationClassEnhancer.java:363)
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$bb6c42e.cloudSqlDataSourceProperties (<generated>)
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.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.java:154)
So it is caused by
Unable to set ApplicationName - SQLAdmin client already initialized.
my build.gradle looks like this
buildscript { // Configuration for building
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.+' // Latest 1.x.x releas
}
}
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
group = 'de.msm'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = 1.8 // App Engine Flexible uses Java 8
configurations {
providedRuntime
compileOnly {
extendsFrom annotationProcessor
}
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
appengine { // App Engine tasks configuration
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
/*
Only for Run
configurations.all {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}*/
repositories {
mavenCentral()
jcenter()
jcenter{
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
task getHomeDir { //To get actual homeDir
doLast {
println gradle.gradleHomeDir
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile('org.springframework.boot:spring-boot-starter-jetty')
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.1.6.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'com.github.javafaker:javafaker:0.17.2'
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.56'
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.1.4.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-mail:2.1.5.RELEASE'
compile 'org.springframework:spring-context-support:5.1.7.RELEASE'
testCompile 'io.rest-assured:rest-assured:4.0.0'
compile 'io.rest-assured:xml-path:4.0.0'
compile 'io.rest-assured:json-path:4.0.0'
testCompile 'io.rest-assured:json-schema-validator:4.0.0'
compile group: 'joda-time', name: 'joda-time', version: '2.10.3'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.1'
testCompile group: 'org.mockito', name: 'mockito-all', version: '2.0.2-beta'
compile group: 'org.xhtmlrenderer', name: 'flying-saucer-pdf', version: '9.1.18'
compile "org.apache.pdfbox:pdfbox-tools:2.0.3"
compile "com.itextpdf:itextpdf:5.5.10"
compile "com.itextpdf.tool:xmlworker:5.5.10"
compile "org.apache.poi:poi-ooxml:3.15"
compile "org.apache.poi:poi-scratchpad:3.15"
compile "xerces:xercesImpl:2.8.0"
compile "org.slf4j:slf4j-nop:1.8.0-beta4"
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile group: 'com.google.cloud', name: 'google-cloud-storage', version: '1.91.0'
compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-sql-postgresql', version: '1.1.3.RELEASE'
compile 'com.google.appengine:appengine-api-1.0-sdk:+'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
}
```
I dont understand whats the problem..
Related
I got a project and it is built with gradle 6 or older version.
I've checked the other stakeoverflow discussion with compile/testCompile problem in gradle 7, and I change all the dependencies from compile/testCompile to api/testImplementation.
But it still doesn't work when I'm doing gradle build.
It still return with Configuration with name 'compile' not found
I've checked this:
Build error with gradle Could not find method testCompile()
What's the difference between implementation, api and compile in Gradle?
Here is my root gradle configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// https://github.com/google/protobuf-gradle-plugin
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
}
}
plugins {
id 'application'
id 'java'
id 'java-library'
id "com.google.protobuf" version "0.8.10"
}
group 'com.ght'
version '61'
mainClassName = 'com.application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
// jcenter() is no longer support.
// jcenter()
mavenCentral()
}
sourceSets {
main {
proto {
srcDir 'src/main/protobuf'
include '**/*.protodevel'
}
}
}
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.0.0'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.3'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-core
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.1.3'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-implementation
implementation group: 'org.slf4j', name: 'slf4j-implementation', version: '1.7.26'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.2.1'
// https://mvnrepository.com/artifact/org.locationtech.jts/jts-core
implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.16.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
// https://mvnrepository.com/artifact/com.vividsolutions/jts
implementation group: 'com.vividsolutions', name: 'jts', version: '1.13'
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation group: 'com.google.guava', name: 'guava', version: '19.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.5'
// https://mvnrepository.com/artifact/commons-logging/commons-logging
implementation group: 'commons-logging', name: 'commons-logging', version: '1.2'
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0'
}
generatedFilesBaseDir = "$projectDir/gen"
}
clean {
delete protobuf.generatedFilesBaseDir
}
jar{
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes('Manifest-Version': archiveVersion, 'Main-Class': 'com.application')
}
exclude 'logback-test.xml'
exclude '**/schema/**'
exclude '**.proto'
}
Here is build error message:
A problem occurred configuring root project 'application'.
> Configuration with name 'compile' not found.
* Try:
> Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'application'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:84)
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:77)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:55)
at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate.run(LifecycleProjectEvaluator.java:255)
.
.
.
Caused by: org.gradle.api.artifacts.UnknownConfigurationException: Configuration with name 'compile' not found.
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.createNotFoundException(DefaultConfigurationContainer.java:108)
at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getByName(DefaultNamedDomainObjectCollection.java:333)
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.getByName(DefaultConfigurationContainer.java:98)
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.getByName(DefaultConfigurationContainer.java:50)
.
.
.
at com.google.protobuf.gradle.ProtobufPlugin$_setupExtractIncludeProtosTask_closure21.doCall(ProtobufPlugin.groovy:369)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:73)
at org.gradle.util.internal.ConfigureUtil.configureTarget(ConfigureUtil.java:155)
at org.gradle.util.internal.ConfigureUtil.configureSelf(ConfigureUtil.java:131)
at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:666)
at org.gradle.api.DefaultTask.configure(DefaultTask.java:309)
.
.
.
gradle version: gradle 7.5
gradle JVM version: GraalVM version 17.0.3
IDE: intellij ide 2022.1.3
Thank you for any help.
You're using a very outdated version of the Protobuf Gradle plugin. Version 0.8.10 (2019) predates Gradle 7 (2021). The issue you're facing is likely to be fixed by upgrading the plugin.
plugins {
id "com.google.protobuf" version "0.8.19"
}
I upgraded the plugin id 'org.springframework.boot' version '2.6.5' which led to the following changes
plugins {
id 'java'
id 'org.springframework.boot' version '2.6.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'jacoco'
id 'org.barfuin.gradle.jacocolog' version '1.0.1'
}
bootRun {
args = [
'--spring.config.location=./src/configs.properties',
]
}
springBoot {
mainClass = 'com.company.service.ServiceClass'
}
jar {
// This would avoid creating an additional "-plain" jar
enabled = true
archiveClassifier = ''
// Before the plugin upgrade I wasnt getting manifest attribute related error. Because of one of such errors, I added it the attribute explicitly.
manifest {
attributes 'Main-Class': 'com.company.service.ServiceClass'
}
}
bootJar {
layered {
enabled = true
}
}
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation 'org.bouncycastle:bcprov-jdk16:1.46'
implementation 'org.immutables:value:2.9.0'
implementation('org.apache.lucene:lucene-core:8.10.0')
implementation('com.fasterxml.jackson.core:jackson-core:2.13.2')
implementation('com.fasterxml.jackson.core:jackson-annotations:2.13.2')
implementation('com.fasterxml.jackson.core:jackson-databind:2.13.2')
implementation('org.apache.poi:poi-ooxml:5.2.2')
implementation('io.netty:netty-codec:4.1.75.Final')
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.13.2'
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.immutables:value:2.9.0'
implementation('org.springframework.boot:spring-boot-starter-web:2.6.5') {
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.slf4j', module: 'slf4j-simple'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.slf4j', module: 'slf4j-simple'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
exclude group: 'ch.qos.logback', module: 'logback-classic'
implementation('org.apache.tomcat.embed:tomcat-embed-core:9.0.54')
}
implementation('org.springframework.boot:spring-boot-starter-security:2.6.5') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.slf4j', module: 'slf4j-simple'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
implementation('org.keycloak:keycloak-spring-boot-starter:17.0.1') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.slf4j', module: 'slf4j-simple'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
implementation('org.keycloak.bom:keycloak-adapter-bom:17.0.1')
implementation('io.springfox:springfox-boot-starter:3.0.0')
implementation('io.springfox:springfox-swagger-ui:3.0.0')
}
// some jacoco and checkstyle configs here.
When I run the jar, I get the following error
>> java -jar build/libs/service-1.0-SNAPSHOT.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
at java.lang.Class.getDeclaredMethods0(Native Method)
From the solutions I found on SO, I added the dependency
implementation group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.46'
But this doesnt work. Plus I am still using jdk8 and there is no org.bouncycastle for jdk8.
Any suggestions how I can work around this exception?
EDIT:
Running the application with intelliJ doesnt throw this problem. But happens when running from command line.
EDIT:
>> % java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)
Full stack trace
% java -jar build/libs/my-service-class.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
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:650)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 7 more
Running the application with intelliJ doesnt throw this problem. But
happens when running from command line.
java -jar build/libs/my-service-class.jar
For executing a jar directly from command line, it should contain manifest information. Assuming the aforementioned jar contain the same as you're facing the the other issue(class def not found) so looks like your jar my-service-class.jar is thin jar and doesn't contain the other dependencies that you've added in the project. Two way to solve this problem. Either you can create uber jar i.e jar with all the dependencies included by using available plugins for the same and then execute the command or just add all the required dependencies into some folder and give path to it while runing the above command.
I've recently started looking at how to sanitise any user inputs to my test api and I came across this tutorial
Before attempting the tutorial I had logging to console with GCP cloud as thats where I want to run my API.
Now after adding owasp esapi my application will not start when using version 2.2.3.1 of esapi. I just by sure luck attempted using a previous version and it works as in the application will start.
Below is the error I get from logback on application start up
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory loaded from file:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.30/e606eac955f55ecf1d8edcccba04eb8ac98088dd/slf4j-simple-1.7.30.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.SimpleLoggerFactory
Again, If I use version 2.2.2.0 I have no issues at all on startup. Can anyone with experience shed some light here. (PLEASE SEE EDIT)
Below is my gradle build file (note I'm also using GCP logging)
plugins {
id "org.springframework.boot" version "2.5.0"
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id "idea"
id 'com.google.cloud.tools.jib' version '3.0.0'
}
group 'network.thefullstack.search-service'
version '1.0'
java {
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
}
jib.from.image = 'openjdk:15-jdk-buster'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
testImplementation group: 'org.springframework.security', name: 'spring-security-test'
implementation group: 'org.springframework.security', name: 'spring-security-oauth2-client'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
implementation('org.springframework.boot:spring-boot-starter-data-elasticsearch')
implementation group: 'org.springframework.data', name: 'spring-data-elasticsearch'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging', version: '1.2.8.RELEASE'
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '3.0.0'
implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.11.2'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
implementation group: 'org.json', name: 'json', version: '20210307'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'org.owasp:dependency-check-gradle:6.1.6'
compile (group: 'org.owasp.esapi', name: 'esapi', version: '2.2.2.0')
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
jar {
manifest {
attributes(
'Main-Class': 'org.test.SearchServiceApplication'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
}
Here is my ESAPI.properties file:
ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactory
Here is an example of where I am logging:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;
import java.util.Arrays;
public class StringToEnumConverter implements Converter<String, Filters> {
private static Logger logger = LoggerFactory.getLogger(StringToEnumConverter.class);
#Override
public Filters convert(String source) {
try {
logger.info("Attempting to convert ENUM param to uppercase {}", source);
return Filters.valueOf(source.toUpperCase());
} catch (IllegalArgumentException e) {
logger.error("Failed to convert ENUM param to uppercase {}", source);
throw new BadFilterRequestException("Error: Filter provide must be one of: " + Arrays.asList(Filters.values()), "Search");
}
}
}
EDIT: Using the older version while it will allow the API to start, it will fire this error message when its envoked:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.owasp.esapi.logging.slf4j.Slf4JLogFactory
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:340)
at org.owasp.esapi.util.ObjFactory.loadClassByStringName(ObjFactory.java:158)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:81)
at org.owasp.esapi.ESAPI.logFactory(ESAPI.java:139)
at org.owasp.esapi.ESAPI.getLogger(ESAPI.java:155)
at org.owasp.esapi.reference.DefaultEncoder.<init>(DefaultEncoder.java:83)
at org.owasp.esapi.reference.DefaultEncoder.getInstance(DefaultEncoder.java:67)
... 46 common frames omitted
Thank you for your time
I am trying to update my Hibernate Gradle project to Java 10. I get the following error:
Caused by: org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null
at org.hibernate.orm.core#5.3.6.Final/org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
at org.hibernate.orm.core#5.3.6.Final/org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.orm.core#5.3.6.Final/org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.orm.core#5.3.6.Final/org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165)
at org.hibernate.orm.core#5.3.6.Final/org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at org.hibernate.orm.core#5.3.6.Final/org.hibernate.cfg.Configuration.configure(Configuration.java:244)
at com.kiryltkach.bettingtools.betstore.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:14)
... 75 more
Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:409)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
at org.hibernate.orm.core#5.3.6.Final/org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:122)
... 81 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276)
... 85 more
I carefully read this answer, and this is my build.gradle file:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'com.project.example.Main'
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.6.0'
}
}
apply plugin: 'com.google.osdetector'
ext.platform = osdetector.os == 'osx' ? 'mac' : osdetector.os == 'windows' ? 'win' : osdetector.os
compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
}
run {
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls',
//'--add-modules', 'java.xml.bind',
//'--add-modules', 'java.se.ee',
'--add-exports', 'javafx.graphics/com.sun.javafx.util=ALL-UNNAMED',
'--add-exports', 'javafx.base/com.sun.javafx.reflect=ALL-UNNAMED',
'--add-exports', 'javafx.base/com.sun.javafx.beans=ALL-UNNAMED'
//--add-exports=javafx.graphics/com.sun.glass.utils=ALL-UNNAMED
//--add-exports=javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
]
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
compile 'org.hibernate:hibernate-core:5.3.6.Final'
compile group: 'postgresql', name: 'postgresql', version: '9.4.1208-jdbc42-atlassian-hosted'
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.1'
compile group: 'org.jsoup', name: 'jsoup', version: '1.11.3'
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
compile group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0.1'
compile group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.1'
compile group: 'javax.activation', name: 'activation', version: '1.1.1'
compile "org.openjfx:javafx-base:11:$platform"
compile "org.openjfx:javafx-graphics:11:$platform"
compile "org.openjfx:javafx-controls:11:$platform"
compile "org.openjfx:javafx-fxml:11:$platform"
compile "org.openjfx:javafx-web:11:$platform"
}
As you see, I've added javax.xml.bind as a dependency, but it seems that hibernate still ignores it. But if I try to add jvm arguments '--add-modules', 'java.xml.bind', I get java.lang.module.ResolutionException: Modules activation and java.activation export package javax.activation to module org.jsoup. So, how can I solve this problem?
Edit: the IDE (in my case eclipse) knows about the class com.sun.xml.bind.v2.ContextFactory (autocomplete is working on this class).
Try to add this dependency:
compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'
And it should work.
I'm trying to build a Java Servlet with gradle gretty plugin (gradle version 3.4).
I have a dependency to another project databaseprovider:1.0-SNAPSHOT (includes connection to the database and some spring definitions...).
When I run the task "gradle war" the .war-file is built properly with all dependencies in WEB-INF/lib.
But when I try to start with "gradle appStart" I have following problem:
What went wrong: Execution failed for task ':appStart'. Could not get
unknown property 'classesDirs' for main classes of type
org.gradle.api.internal.tasks.DefaultSourceSetOutput.
Caused by: groovy.lang.MissingPropertyException: Could not get unknown
property 'classesDirs' for main classes of type
org.gradle.api.internal.tasks.DefaultSourceSetOutput.
Without the dependency databaseprovider:1.0-SNAPSHOT the jetty starts without problems:
INFO Jetty 9.2.22.v20170606 started and listening on port 8080
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.akhikhl.gretty:gretty:+"
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE"
}
}
apply plugin:'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
repositories {
maven {
url "http://..."
}
mavenLocal()
}
dependencies {
compile('databaseprovider:1.0-SNAPSHOT'){
changing=true
}
}
gretty {
httpPort = 8080
contextPath = '/'
servletContainer = 'jetty9'
}
build.gradle from databaseprovider:
buildscript {
repositories {
maven {
url "http://..."
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply from: 'liquibase.gradle'
jar {
baseName = 'databaseprovider'
version = '1.0-SNAPSHOT'
}
repositories {
maven {
url "http://..."
}
mavenLocal()
jcenter()
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.4.0.RELEASE")
compile group: 'org.springframework.data', name: 'spring-data-jpa', version:'1.10.2.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '5.0.9.Final'
testRuntime group: 'com.h2database', name: 'h2', version: '1.4.192'
compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.0.13'
compile group: 'ch.qos.logback', name: 'logback-core', version:'1.0.13'
compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.5'
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version:'1.7.5'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version:'1.7.5'
compile group: 'org.reflections', name: 'reflections', version: '0.9.11'
compile (group: 'com.mattbertolini', name: 'liquibase-slf4j', version: "1.2.1")
compile (group: 'org.liquibase', name: 'liquibase-core', version: "3.5.3")
compile group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final'
testCompile("junit:junit")
runtime("mysql:mysql-connector-java:5.1.39")
testCompile("org.springframework:spring-test")
}
I was able to solve the problem by adding the version of gretty:
After I changed the classpath in build.gradle
classpath "org.akhikhl.gretty:gretty:+"
to
classpath "org.akhikhl.gretty:gretty:1.4.2"
(compatible version to gradle 3.4) jetty starts without exceptions.
I found this question by googling for the error message when I encountered this issue. For me, I found my answer in this Github thread. Basically, by upgrading my version of Gradle to 4.8 I was able to resolve the issue.