I migrate my app from Spring Boot 1.5.22 to 2.7.0 and I have a problem. Java 8. To migrate to 2.0.0 I have to replace save () with saveAll (), replace the postgres driver: compile group: 'postgresql', name: 'postgresql', version: '9.1-901-1.jdbc4' with implementation ' org.postgresql: postgresql: 42.2.9 ', I also add this line to application.properties:
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = true. After that, I build without mistakes, but precisely: when I start shooting with Postman, with the correct token I get 401. (Before it was 200). When I started analyzing it, it turned out that after Spring migration, when the project is being built, postgres tables on localhost are created correctly, but they are empty, (that's why I get 401). I don't know how to work around it. Would you have an idea? I'm pasting build.gradle:
import org.apache.tools.ant.filters.ReplaceTokens
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE'
}
}
plugins {
id "io.franzbecker.gradle-lombok" version "1.11"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
project.version = '1.1.5'
jar {
baseName = 'refurbishment'
version = project.version
}
sourceSets {
util {
compileClasspath += sourceSets.main.runtimeClasspath
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven { url "http://projectlombok.org/mavenrepo" }
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.5.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version:'1.5.8.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-jwt', version:'1.1.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'1.5.8.RELEASE'
implementation 'org.springframework.boot:spring-boot-properties-migrator:2.1.18.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test'
compile group: 'org.hibernate', name: 'hibernate-validator', version:'5.2.4.Final'
compile group: 'com.google.guava', name: 'guava', version:'16.0.1'
compile group: 'joda-time', name: 'joda-time', version:'2.8.2'
compile group: 'commons-lang', name: 'commons-lang', version:'2.6'
compile group: 'net.sf.ehcache', name: 'ehcache-core', version:'2.6.9'
implementation 'org.postgresql:postgresql:42.2.9'
compile group: 'io.jsonwebtoken', name: 'jjwt', version:'0.6.0'
compile group: 'org.projectlombok', name: 'lombok', version:'1.16.6'
compile group: 'org.apache.commons', name: 'commons-csv', version:'1.2'
compile group: 'com.google.code.gson', name: 'gson', version:'2.6.2'
compile group: 'commons-io', name: 'commons-io', version:'2.4'
compile group: 'org.json', name: 'json', version:'20160212'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version:'2.5.0'
compile group: 'io.springfox', name: 'springfox-swagger2', version:'2.5.0'
compile group: 'com.fasterxml', name: 'classmate', version:'1.3.1'
compile 'com.microsoft.azure:azure-storage:5.4.0'
runtime group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.3.4.jre8-preview'
compile files('libs/PDFjet-5.1.jar')
testCompile(group: 'junit', name: 'junit')
//DBUnit
testCompile 'org.dbunit:dbunit:2.5.3'
testCompile 'com.github.springtestdbunit:spring-test-dbunit:1.3.0'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
testCompile group: 'org.assertj', name: 'assertj-core', version:'1.7.0'
testCompile(group: 'org.mockito', name: 'mockito-core', version:'1.10.19') {
exclude(module: 'hamcrest-core')
}
testCompile group: 'org.springframework', name: 'spring-test', version:'4.2.6.RELEASE'
testCompile group: 'com.jayway.jsonpath', name: 'json-path', version:'2.0.0'
testCompile group: 'com.jayway.jsonpath', name: 'json-path-assert', version:'0.9.1'
}
bootRun {
def profiles = findProperty('profiles')
if (profiles) {
args = ["--spring.profiles.active=" + profiles]
}
}
task copyWebConfig(type: Copy) {
from('src/main/templates') {
include 'web.config'
}
into "$buildDir/libs"
filter(ReplaceTokens, tokens: [VERSION: project.version])
inputs.property("VERSION", project.version)
}
assemble.dependsOn(copyWebConfig)
Solved :) Added spring.datasource.initialization-mode=always to application.properties (working for Spring Boot 2.0.0)
i have a set of code that is using gradle to run the back end server. I am running gradle :bootRun in my terminal. When i run it, it begins to process and then throws this huge error about file location. How can I fix this if i can even fix this.
Parallel execution is an incubating feature.
> Configure project :owf-example-widgets
Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0
at build_cnhv1cccaip845qupsm2wplss.run(C:\Users\ojandali\Desktop\ozone-temp-goss\ozone-framework-server\owf-framework\owf-example-widgets\build.gradle:31)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'owf-framework'.
> Could not resolve all files for configuration ':runtime'.
> Could not find org.ozoneplatform:owf-appconfig:0.9.1-0.
Searched in the following locations:
file:/C:/Users/ojandali/.m2/repository/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.pom
file:/C:/Users/ojandali/.m2/repository/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.jar
https://repo1.maven.org/maven2/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.pom
https://repo1.maven.org/maven2/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.jar
https://repo.grails.org/grails/core/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.pom
https://repo.grails.org/grails/core/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.jar
http://repository.springsource.com/maven/bundles/release/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.pom
http://repository.springsource.com/maven/bundles/release/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.jar
http://repository.springsource.com/maven/bundles/external/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.pom
http://repository.springsource.com/maven/bundles/external/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.jar
https://packages.atlassian.com/3rdparty/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.pom
https://packages.atlassian.com/3rdparty/org/ozoneplatform/owf-appconfig/0.9.1-0/owf-appconfig-0.9.1-0.jar
Required by:
project :
> Could not find org.ozoneplatform:owf-auditing:1.3.2-0.
Searched in the following locations:
file:/C:/Users/ojandali/.m2/repository/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.pom
file:/C:/Users/ojandali/.m2/repository/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.jar
https://repo1.maven.org/maven2/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.pom
https://repo1.maven.org/maven2/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.jar
https://repo.grails.org/grails/core/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.pom
https://repo.grails.org/grails/core/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.jar
http://repository.springsource.com/maven/bundles/release/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.pom
http://repository.springsource.com/maven/bundles/release/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.jar
http://repository.springsource.com/maven/bundles/external/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.pom
http://repository.springsource.com/maven/bundles/external/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.jar
https://packages.atlassian.com/3rdparty/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.pom
https://packages.atlassian.com/3rdparty/org/ozoneplatform/owf-auditing/1.3.2-0/owf-auditing-1.3.2-0.jar
Required by:
project :
> Could not find org.ozoneplatform:owf-security:4.0.4-0.
Searched in the following locations:
file:/C:/Users/ojandali/.m2/repository/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.pom
file:/C:/Users/ojandali/.m2/repository/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.jar
https://repo1.maven.org/maven2/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.pom
https://repo1.maven.org/maven2/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.jar
https://repo.grails.org/grails/core/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.pom
https://repo.grails.org/grails/core/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.jar
http://repository.springsource.com/maven/bundles/release/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.pom
http://repository.springsource.com/maven/bundles/release/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.jar
http://repository.springsource.com/maven/bundles/external/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.pom
http://repository.springsource.com/maven/bundles/external/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.jar
https://packages.atlassian.com/3rdparty/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.pom
https://packages.atlassian.com/3rdparty/org/ozoneplatform/owf-security/4.0.4-0/owf-security-4.0.4-0.jar
Required by:
project :
> Could not find org.ozoneplatform:owf-messaging:1.19.1-0.
Searched in the following locations:
file:/C:/Users/ojandali/.m2/repository/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.pom
file:/C:/Users/ojandali/.m2/repository/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.jar
https://repo1.maven.org/maven2/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.pom
https://repo1.maven.org/maven2/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.jar
https://repo.grails.org/grails/core/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.pom
https://repo.grails.org/grails/core/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.jar
http://repository.springsource.com/maven/bundles/release/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.pom
http://repository.springsource.com/maven/bundles/release/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.jar
http://repository.springsource.com/maven/bundles/external/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.pom
http://repository.springsource.com/maven/bundles/external/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.jar
https://packages.atlassian.com/3rdparty/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.pom
https://packages.atlassian.com/3rdparty/org/ozoneplatform/owf-messaging/1.19.1-0/owf-messaging-1.19.1-0.jar
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 10s
I am trying to figure out why the files are not being located or found.
UPDATE
this is the build.gradle file... I am trying to run gradle :bootRun
buildscript {
ext {
grailsVersion = '3.3.2'
gormVersion = '6.1.8.RELEASE'
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://repo.grails.org/grails/core' }
jcenter()
}
dependencies {
classpath group: 'io.spring.gradle', name: 'dependency-management-plugin', version: '1.0.4.RELEASE'
classpath group: 'org.grails', name: 'grails-gradle-plugin', version: grailsVersion
classpath group: 'org.grails.plugins', name: 'hibernate5', version: gormVersion - ".RELEASE"
classpath group: 'org.grails.plugins', name: 'database-migration', version: '3.0.3'
}
}
group 'org.ozoneplatform'
version '7.17.2-0'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'org.grails.grails-web'
apply plugin: 'org.grails.grails-gsp'
ext {
releaseVersion = version.toString().replaceFirst("-", ".")
tomcatBundleStaging = "$buildDir/staging/bundle"
}
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://repo.grails.org/grails/core' }
maven { url 'http://repository.springsource.com/maven/bundles/release' }
maven { url 'http://repository.springsource.com/maven/bundles/external' }
maven { url 'https://packages.atlassian.com/3rdparty/' }
}
dependencyManagement {
imports {
mavenBom 'org.grails:grails-bom:' + grailsVersion
mavenBom 'org.ozoneplatform:ozone-classic-bom:7.17.2-0'
}
applyMavenExclusions false
}
grails {
plugins {
compile project(':owf-example-widgets')
}
}
configurations {
customTomcat {}
drivers {}
runtime.extendsFrom drivers
}
dependencies {
// Ozone
compile group: 'org.ozoneplatform', name: 'owf-appconfig', version: '0.9.1-0'
compile group: 'org.ozoneplatform', name: 'owf-auditing', version: '1.3.2-0'
compile group: 'org.ozoneplatform', name: 'owf-security', version: '4.0.4-0'
compile group: 'org.ozoneplatform', name: 'owf-messaging', version: '1.19.1-0'
customTomcat(group: 'org.ozoneplatform', name: 'owf-custom-tomcat', version: '1.2.3-0') {
artifact {
name = 'owf-custom-tomcat'
type = 'zip'
}
}
// Spring Boot
compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging'
provided group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat'
// Grails
compile group: 'org.grails', name: 'grails-core'
compile group: 'org.grails', name: 'grails-web-boot'
compile group: 'org.grails', name: 'grails-logging'
compile group: 'org.grails', name: 'grails-plugin-rest'
compile group: 'org.grails', name: 'grails-plugin-databinding'
compile group: 'org.grails', name: 'grails-plugin-i18n'
compile group: 'org.grails', name: 'grails-plugin-services'
compile group: 'org.grails', name: 'grails-plugin-url-mappings'
compile group: 'org.grails', name: 'grails-plugin-interceptors'
compile group: 'org.grails.plugins', name: 'cache'
compile group: 'org.grails.plugins', name: 'cache-ehcache'
compile group: 'org.ehcache', name: 'ehcache'
compile group: 'org.grails.plugins', name: 'async'
compile group: 'org.grails.plugins', name: 'scaffolding'
compile group: 'org.grails.plugins', name: 'events'
compile group: 'org.grails.plugins', name: 'hibernate5'
compile group: 'org.grails.plugins', name: 'gsp'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind'
console group: 'org.grails', name: 'grails-console'
profile group: 'org.grails.profiles', name: 'web'
runtime group: 'org.glassfish.web', name: 'el-impl'
runtime group: 'com.h2database', name: 'h2'
runtime group: 'org.apache.tomcat', name: 'tomcat-jdbc'
drivers group: 'org.postgresql', name: 'postgresql'
testCompile group: 'org.grails', name: 'grails-gorm-testing-support'
testCompile group: 'org.grails', name: 'grails-web-testing-support'
testCompile group: 'org.grails', name: 'grails-datastore-rest-client'
testRuntime group: 'cglib', name: 'cglib-nodep'
// Grails Plugins
compile group: 'org.grails.plugins', name: 'converters'
compile group: 'org.grails.plugins', name: 'quartz'
compile group: 'org.grails.plugins', name: 'grails-pretty-time'
// Other
compile group: 'com.google.code.findbugs', name: 'jsr305'
compile group: 'org.hibernate', name: 'hibernate-core'
compile group: 'org.apache.httpcomponents', name: 'httpcore'
compile group: 'org.apache.httpcomponents', name: 'httpclient'
compile group: 'commons-fileupload', name: 'commons-fileupload'
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always',
'-Duser=testAdmin1',
'-Dowf.db.init',
'-Ddisable.auto.recompile=false',
'-Xverify:none')
addResources = false
}
war {
// Exclude the Spring .xml configuration files from the .war
// They will be copied to the Tomcat classpath at /tomcat/libs
rootSpec.exclude('ozone/framework/**')
}
idea {
module {
excludeDirs += file('archive')
excludeDirs += file('src/main/resources/public')
}
}
apply from: 'gradle/create-bundle.gradle'
apply from: 'gradle/report-test-coverage.gradle'
task wrapper(type: Wrapper) {
gradleVersion = '4.2.1'
}
I cannot find
compile group: 'org.ozoneplatform', name: 'owf-appconfig', version: '0.9.1-0'
compile group: 'org.ozoneplatform', name: 'owf-auditing', version: '1.3.2-0'
compile group: 'org.ozoneplatform', name: 'owf-security', version: '4.0.4-0'
compile group: 'org.ozoneplatform', name: 'owf-messaging', version: '1.19.1-0'
on Maven Central, I suspect that is the issue, because that is
They seem to have different names, see:
https://search.maven.org/search?q=g:org.ozoneplatform
For example
compile group: 'org.ozoneplatform', name: 'ozone-security', version: '4.0.3'
should work.
It is also possible for you to build the missing dependencies yourself, for example by checking out this repository and doing a build:
https://github.com/ozoneplatform/owf-security
I try to run project with gretty. It throws exception:
10:47:39 WARN Failed startup of context o.a.g.JettyWebAppContext#52045dbe{/,file:/C:/IdeaProjects/example-tab/build/inplaceWebapp/,STARTING}
java.lang.RuntimeException: Error scanning entry module-info.class from jar file:/C:/Users/user1/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.10.0/fec5797a55b786184a537abd39c3fa1449d752d6/log4j-api-2.10.0.jar
at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:913) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:831) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:164) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:549) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) ~[jetty-util-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) ~[jetty-util-9.2.24.v20180105.jar:9.2.24.v20180105]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
Caused by: java.lang.UnsupportedOperationException: null
at org.objectweb.asm.ClassVisitor.visitModule(ClassVisitor.java:129) ~[asm-6.1.1.jar:na]
at org.objectweb.asm.ClassReader.readModule(ClassReader.java:667) ~[asm-6.1.1.jar:na]
at org.objectweb.asm.ClassReader.accept(ClassReader.java:503) ~[asm-6.1.1.jar:na]
at org.objectweb.asm.ClassReader.accept(ClassReader.java:355) ~[asm-6.1.1.jar:na]
at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:974) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry(AnnotationParser.java:956) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:909) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
... 6 common frames omitted
gradle:
plugins {
id 'java'
id 'war'
id "org.gretty" version "2.2.0"
}
group 'ru.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
ext {
SPRING_VERSION = '5.1.0.RELEASE'
JUNIT_VERSION = '5.3.1'
JACKSON_VERSION = '2.9.7'
}
repositories {
mavenCentral()
jcenter()
maven {
url 'https://oss.sonatype.org/content/repositories/releases/'
}
}
gretty {
springBootVersion = '2.0.5.RELEASE'
contextPath = "/"
}
dependencies {
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compileOnly group: 'com.google.appengine', name: 'appengine-endpoints-deps', version: '1.9.65'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile group: 'org.springframework', name: 'spring-webmvc', version: SPRING_VERSION
compile group: 'org.springframework', name: 'spring-web', version: SPRING_VERSION
compile group: 'org.springframework', name: 'spring-jdbc', version: SPRING_VERSION
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.5.RELEASE'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.5.2'
compile group: 'com.zaxxer', name: 'HikariCP', version: '3.2.0'
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.3.0'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: JACKSON_VERSION
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: JACKSON_VERSION
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: JUNIT_VERSION
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: JUNIT_VERSION
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.3.1'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.22.0'
testCompile group: 'org.springframework', name: 'spring-test', version: SPRING_VERSION
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
testCompile group: 'com.jayway.jsonpath', name: 'json-path-assert', version: '2.4.0'
}
test {
useJUnitPlatform()
}
Scanning internet not helped. Please advice how to run it correctly. I had problems with downloading dependencies from jcenter(), may be, problem is here.
Validator write that my question have mostly code, but I have no Idea what to add to my explain, than, my apologies, I'll quote Steve Jobs:
“You can’t connect the dots looking forward; you can only connect them looking backward. So you have to trust that the dots will somehow connect in your future.”
You introduced a JEP-238 Jar file into your project: log4j-api-2.10.0.jar
Support for JEP-238 Jar files on any Java Runtime (doesn't matter if it's Java 7, Java 8, Java 9, Java 10, Java 11, or even the new Java 12-ea releases) was first introduced in Jetty 9.4.9.
You have 2 options:
Don't use JEP-238 Jar Files in your project.
Upgrade to Jetty 9.4.9 (or newer) to have support for JEP-238 Jar Files.
See past answers:
https://stackoverflow.com/a/45362629/775715
https://stackoverflow.com/a/52722120/775715
I try to configure log4j2 to use MongoDB in a gradle project, when I run in Eclipse and my tests it's work fine, but When I generate a jar and start it I get a error:
2018-08-13 09:30:11,534 main ERROR Unable to locate plugin type for MongoDb
2018-08-13 09:30:11,548 main ERROR Unable to locate plugin for MongoDb
2018-08-13 09:30:11,597 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender for element NoSql: java.lang.NullPointerException java.lang.NullPointerException
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.findNamedNode(PluginElementVisitor.java:103)
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:87)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:181)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at br.com.serversocket.main.Main.(Main.java:15)
2018-08-13 09:30:11,607 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender for element NoSql: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:235)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at br.com.serversocket.main.Main.(Main.java:15)
2018-08-13 09:30:11,617 main ERROR Null object returned for NoSql in appenders.
2018-08-13 09:30:11,655 main ERROR Unable to locate appender "NoSql" for logger config "root"
my log4j2.yaml:
Configuration:
status: WARN
appenders:
NoSql:
name: NoSql
MongoDb:
databaseName: tracker
collectionName: appLog
server: ds261755.mlab.com
port: 61755
username: admin
password: XXXXX
Loggers:
logger:
-
name: com.memorynotfound
level: info
-
name: com.mchange.v2.c3p0
level: warn
Root:
level: info
AppenderRef:
ref: NoSql
my buil.gradle:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
archivesBaseName = 'ServerSocket'
version = '3.2.1'
mainClassName = 'br.com.serversocket.main.Main'
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
jar {
dependsOn 'test'
archiveName = "ServerSocket.jar"
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'br.com.serversocket.main.Main'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
test{
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
testLogging {
exceptionFormat = 'full'
}
}
eclipse.classpath.file.whenMerged {
entries.each { println it.path }
}
configurations {
providedCompile
}
repositories {
mavenCentral()
mavenLocal()
}
ext {
jacksonVersion = '2.9.1'
hibernateVerison = '5.1.0.Final'
slf4jVerison = '1.7.25'
log4jVerison = '2.11.1'
junitVersion = '5.2.0'
emailVersion = '1.6.1'
}
dependencies {
//compile files(fileTree(dir: 'lib', includes: ['*.jar']))
compile "org.hibernate:hibernate-jpamodelgen:${hibernateVerison}"
compile "org.hibernate:hibernate-c3p0:${hibernateVerison}"
compile "org.hibernate:hibernate-core:${hibernateVerison}"
compile "org.hibernate:hibernate-entitymanager:${hibernateVerison}"
compile "org.slf4j:slf4j-simple:${slf4jVerison}"
compile "org.slf4j:slf4j-api:${slf4jVerison}"
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-api:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-core:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-nosql:2.9.1"
compile "org.apache.logging.log4j:log4j-jcl:${log4jVerison}"
compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
compile "javax.mail:javax.mail-api:${emailVersion}"
compile "com.sun.mail:javax.mail:${emailVersion}"
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.44'
compile group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '5.0.1.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.2.1'
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.0'
compile group: 'org.jboss.logging', name: 'jboss-logging', version: '3.3.1.Final'
compile group: 'commons-logging', name: 'commons-logging', version: '1.0.3'
compile group: 'org.apache.mina', name: 'mina-core', version: '2.0.19'
compile group: 'antlr', name: 'antlr', version: '2.7.7'
compile group: 'com.fasterxml', name: 'classmate', version: '1.3.0'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.6'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.5'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.3'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
compile group: 'net.sf.ehcache', name: 'ehcache', version: '1.5.0'
compile group: 'org.apache.geronimo.specs', name: 'geronimo-jta_1.1_spec', version: '1.1.1'
compile group: 'org.jboss', name: 'jandex', version: '2.0.3.Final'
compile group: 'org.javassist', name: 'javassist', version: '3.22.0-GA'
compile group: 'jdom', name: 'jdom', version: '1.1'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'com.mchange', name: 'mchange-commons-java', version: '0.2.3.4'
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.8.0'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.2.0'
}
configurations {
all*.exclude group: 'javassist', module: 'javassist'
}
My problem is in configuration? What I need to do?
[EDITED]
I change some configurations:
build.gradle:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
archivesBaseName = 'ServerSocket'
version = '3.2.1'
mainClassName = 'br.com.serversocket.main.Main'
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
jar {
//dependsOn 'test'
archiveName = "ServerSocket.jar"
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'br.com.serversocket.main.Main'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
test{
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
testLogging {
exceptionFormat = 'full'
}
}
eclipse.classpath.file.whenMerged {
entries.each { println it.path }
}
configurations {
providedCompile
}
repositories {
mavenCentral()
mavenLocal()
}
ext {
jacksonVersion = '2.9.1'
hibernateVerison = '5.1.0.Final'
slf4jVerison = '1.7.25'
log4jVerison = '2.11.1'
junitVersion = '5.2.0'
emailVersion = '1.6.1'
mongoDBVersion = '3.8.0'
}
dependencies {
//compile files(fileTree(dir: 'lib', includes: ['*.jar']))
compile "org.hibernate:hibernate-jpamodelgen:${hibernateVerison}"
compile "org.hibernate:hibernate-c3p0:${hibernateVerison}"
compile "org.hibernate:hibernate-core:${hibernateVerison}"
compile "org.hibernate:hibernate-entitymanager:${hibernateVerison}"
compile "org.slf4j:slf4j-simple:${slf4jVerison}"
compile "org.slf4j:slf4j-api:${slf4jVerison}"
compile "org.apache.logging.log4j:log4j-api:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-core:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-jcl:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-mongodb3:${log4jVerison}"
//compile "org.apache.logging.log4j:log4j-nosql:${log4jVerison}"
compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
compile "javax.mail:javax.mail-api:${emailVersion}"
compile "com.sun.mail:javax.mail:${emailVersion}"
//compile "org.mongodb:mongo-java-driver:${mongoDBVersion}"
compile "org.mongodb:mongodb-driver:${mongoDBVersion}"
compile "org.mongodb:mongodb-driver-core:${mongoDBVersion}"
compile "org.mongodb:bson:${mongoDBVersion}"
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.44'
compile group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '5.0.1.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.2.1'
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.0'
compile group: 'org.jboss.logging', name: 'jboss-logging', version: '3.3.1.Final'
compile group: 'commons-logging', name: 'commons-logging', version: '1.0.3'
compile group: 'org.apache.mina', name: 'mina-core', version: '2.0.19'
compile group: 'antlr', name: 'antlr', version: '2.7.7'
compile group: 'com.fasterxml', name: 'classmate', version: '1.3.0'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.6'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.5'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.3'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
compile group: 'net.sf.ehcache', name: 'ehcache', version: '1.5.0'
compile group: 'org.apache.geronimo.specs', name: 'geronimo-jta_1.1_spec', version: '1.1.1'
compile group: 'org.jboss', name: 'jandex', version: '2.0.3.Final'
compile group: 'org.javassist', name: 'javassist', version: '3.22.0-GA'
compile group: 'jdom', name: 'jdom', version: '1.1'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'com.mchange', name: 'mchange-commons-java', version: '0.2.3.4'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.2.0'
}
configurations {
all*.exclude group: 'javassist', module: 'javassist'
}
log4j2.yaml:
Configuration:
status: WARN
appenders:
NoSql:
name: databaseAppender
MongoDb3:
databaseName: tracker
collectionName: appLog
server: ds261755.mlab.com
port: 61755
username: admin
password: xxxx
Loggers:
logger:
-
name: com.memorynotfound
level: info
-
name: com.mchange.v2.c3p0
level: warn
Root:
level: info
AppenderRef:
ref: databaseAppender
and I get a new error message:
2018-08-14 10:29:26,690 main ERROR Unable to locate plugin type for MongoDb3
2018-08-14 10:29:26,703 main ERROR Unable to locate plugin for MongoDb3
2018-08-14 10:29:26,753 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender for element NoSql: java.lang.NullPointerException java.lang.NullPointerException
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.findNamedNode(PluginElementVisitor.java:103)
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:87)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:181)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at br.com.serversocket.main.Main.<clinit>(Main.java:15)
2018-08-14 10:29:26,764 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender for element NoSql: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:235)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at br.com.serversocket.main.Main.<clinit>(Main.java:15)
2018-08-14 10:29:26,773 main ERROR Null object returned for NoSql in appenders.
2018-08-14 10:29:26,813 main ERROR Unable to locate appender "databaseAppender" for logger config "root"
I inspected class' log4j-core to try understend better about the error and found this method:
protected void preConfigure(final Node node) {
try {
for (final Node child : node.getChildren()) {
if (child.getType() == null) {// problem happen here in production
LOGGER.error("Unable to locate plugin type for " + child.getName());
continue;
}
final Class<?> clazz = child.getType().getPluginClass();
if (clazz.isAnnotationPresent(Scheduled.class)) {
configurationScheduler.incrementScheduledItems();
}
preConfigure(child);
}
} catch (final Exception ex) {
LOGGER.error("Error capturing node data for node " + node.getName(), ex);
}
}
When I run project in IDE a node's property "getType()" is "PluginType [pluginClass=class org.apache.logging.log4j.mongodb3.MongoDbProvider, key=mongodb3, elementName=MongoDb3, isObjectPrintable=true, isDeferChildren==false, category=core]"
but I production, I suppose how the jar not found a class inside log4j-mongodb3.
I inspect generated jar, but the class was packaged without problems. what is happen ?
[EDITED]
I found my problem, I created a test project without gradle and I generated a jar, I need to copy dependencies and not extract they, how can I configure gradle to do it in jar task ?
I solved my problem using 2 gradle's plugin:
shadow:
http://imperceptiblethoughts.com/shadow/#shadowing_gradle_plugins
and this plugin to fix a incompability with log4j:
https://github.com/TheBoegl/shadow-log4j-transformer#using-the-gradle-plugin-dsl
follow my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
classpath 'de.sebastianboegl.gradle.plugins:shadow-log4j-transformer:2.2.0'
}
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'com.github.johnrengelman.shadow'
archivesBaseName = 'ServerSocket'
version = '3.2.1'
mainClassName = 'br.com.serversocket.main.Main'
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
shadowJar {
//dependsOn 'test'
transform(de.sebastianboegl.gradle.plugins.shadow.transformers.Log4j2PluginsFileTransformer)
archiveName = "ServerSocket.jar"
manifest {
attributes 'Main-Class': 'br.com.serversocket.main.Main'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
jar {
//dependsOn 'test'
archiveName = "ServerSocket.jar"
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'br.com.serversocket.main.Main'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
test{
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
testLogging {
exceptionFormat = 'full'
}
}
eclipse.classpath.file.whenMerged {
entries.each { println it.path }
}
configurations {
providedCompile
}
repositories {
mavenCentral()
mavenLocal()
}
ext {
jacksonVersion = '2.9.1'
hibernateVerison = '5.1.0.Final'
slf4jVerison = '1.7.25'
log4jVerison = '2.11.1'
junitVersion = '5.2.0'
emailVersion = '1.6.1'
mongoDBVersion = '3.8.0'
}
dependencies {
//compile files(fileTree(dir: 'lib', includes: ['*.jar']))
compile "org.hibernate:hibernate-jpamodelgen:${hibernateVerison}"
compile "org.hibernate:hibernate-c3p0:${hibernateVerison}"
compile "org.hibernate:hibernate-core:${hibernateVerison}"
compile "org.hibernate:hibernate-entitymanager:${hibernateVerison}"
compile "org.slf4j:slf4j-simple:${slf4jVerison}"
compile "org.slf4j:slf4j-api:${slf4jVerison}"
compile "org.apache.logging.log4j:log4j-api:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-core:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-mongodb3:${log4jVerison}"
compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
compile "javax.mail:javax.mail-api:${emailVersion}"
compile "com.sun.mail:javax.mail:${emailVersion}"
compile "org.mongodb:mongodb-driver:${mongoDBVersion}"
compile "org.mongodb:mongodb-driver-core:${mongoDBVersion}"
compile "org.mongodb:bson:${mongoDBVersion}"
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.44'
compile group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '5.0.1.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.2.1'
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.0'
compile group: 'org.jboss.logging', name: 'jboss-logging', version: '3.3.1.Final'
compile group: 'commons-logging', name: 'commons-logging', version: '1.0.3'
compile group: 'org.apache.mina', name: 'mina-core', version: '2.0.19'
compile group: 'antlr', name: 'antlr', version: '2.7.7'
compile group: 'com.fasterxml', name: 'classmate', version: '1.3.0'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.6'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.5'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.3'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
compile group: 'net.sf.ehcache', name: 'ehcache', version: '1.5.0'
compile group: 'org.apache.geronimo.specs', name: 'geronimo-jta_1.1_spec', version: '1.1.1'
compile group: 'org.jboss', name: 'jandex', version: '2.0.3.Final'
compile group: 'org.javassist', name: 'javassist', version: '3.22.0-GA'
compile group: 'jdom', name: 'jdom', version: '1.1'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'com.mchange', name: 'mchange-commons-java', version: '0.2.3.4'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.2.0'
}
configurations {
all*.exclude group: 'javassist', module: 'javassist'
}
I'm new to Java projects and gradle. I'm trying to use Google's GSON to parse a JSON string.
When I navigate to my-project-name/build/classes/main/
I get the ClassNotFoundException when I run
$ java GetGroupMeMessages
Here is the stack trace (That's what it's called, right?):
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/Gson
at GetGroupMeMessages.main(GetGroupMeMessages.java:59)
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
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 file looks like this:
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'gscc-groupme-logs',
'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
I'm doing everything from the command line.
I've got my files saved under my-project-name/src/main/java/
Any help is much appreciated! I am stuck.
If you want to run single java file from command line, you need to provide gson jar as classpath using -cp jar_location in your command.
If you want to run build jar:
change dependencies from compile to runtime in your configuration.
dependencies {
runtime group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
runtime group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
runtime group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Change your jar config like following:
jar {
manifest {
attributes(
'Implementation-Title': 'gscc-groupme-logs',
'Implementation-Version': version
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'GetGroupMeMessages'
)
}
}
Then after creating the jar run it using java -jar jarname command.