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.
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 am getting the following error when I build my project, I tried various other StackOverflow answers but all in vain.
Also tried to exclude logback from all the dependencies,
configurations {
implementation {
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
}
And the above does solve the problem but gives another error java.lang.NoClassDefFoundError: ch/qos/logback/classic/turbo/TurboFilter, seems like it is using logback some place else and hence logback cannot be excluded from all the dependencies. Any suggestion on how to get rid of the issue would be really valuable. Thanks.
Error log
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a
Logback LoggerContext but Logback is on the classpath. Either remove
Logback or the competing implementation (class
org.jboss.slf4j.JBossLoggerFactory loaded from
file:/C:/Users/idnpga/.gradle/caches/modules-2/files-2.1/org.infinispan/infinispan-embedded/9.1.7.Final/6b94fd0e5872b8ce90ab35531afe90d1efaf36f0/infinispan-embedded-9.1.7.Final.jar).
If you are using WebLogic you will need to add 'org.slf4j' to
prefer-application-packages in WEB-INF/weblogic.xml:
org.jboss.slf4j.JBossLoggerFactory at
org.springframework.util.Assert.instanceCheckFailed(Assert.java:696)
at org.springframework.util.Assert.isInstanceOf(Assert.java:596) at
org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:284)
at
org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:104)
at
org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:232)
at
org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at
org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:74)
at
org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
at
org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
at
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
... 81 more
build.gradle
dependencies {
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-amqp')
implementation('org.springframework.boot:spring-boot-starter-data-mongodb')
implementation('org.springframework.boot:spring-boot-starter-data-rest')
implementation('org.springframework.boot:spring-boot-starter-integration')
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.boot:spring-boot-starter-thymeleaf') {
exclude group: 'org.codehaus.groovy', module: 'groovy'
}
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-web-services')
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-config', version: '2.0.5.RELEASE'
implementation('org.springframework.data:spring-data-rest-hal-explorer')
implementation('org.springframework.integration:spring-integration-amqp')
implementation('org.springframework.integration:spring-integration-mongodb')
implementation('org.springframework.integration:spring-integration-file')
implementation('org.springframework.integration:spring-integration-http')
implementation('org.springframework.integration:spring-integration-ip')
implementation('org.springframework.integration:spring-integration-sftp')
implementation('org.springframework.integration:spring-integration-stream')
implementation('org.springframework.integration:spring-integration-xml')
implementation('org.springframework.ws:spring-ws-security') {
exclude group: 'org.opensaml:opensaml-saml-impl'
}
implementation ('org.springframework.security:spring-security-oauth2-core') {
exclude group: 'org.codehaus.jackson'
}
implementation group: 'org.springframework.data', name: 'spring-data-mongodb', version: '3.0.4.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix', version: '2.1.5.RELEASE'
implementation 'org.infinispan:infinispan-spring-boot-starter-parent:14.0.0.Dev01'
implementation 'org.infinispan:spring-boot-starter-infinispan-autoconfigure:1.0.0'
implementation('org.infinispan:infinispan-embedded:9.1.7.Final')
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.9'
testImplementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.9'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module : 'junit-vintage-engine'
}
testImplementation('org.springframework.ws:spring-ws-test')
testImplementation("org.springframework.cloud:spring-cloud-contract-wiremock:3.1.1")
testImplementation("org.springframework.cloud:spring-cloud-starter-contract-verifier") {
exclude group: 'org.springframework.boot', module : 'spring-boot-starter-test'
}
}
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'm trying to connect to HiveServer2 and run queries from my java application. When I run on my localserver(Hive version: 2.1.1). It works perfectly with the following dependencies:
compile('org.apache.hadoop:hadoop-core:1.2.1')
compile ('org.apache.hive:hive-jdbc:2.1.0'){
exclude group: 'org.eclipse.jetty.aggregate', module: '*'
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j" }
compile ('org.apache.hadoop:hadoop-common:3.0.0'){
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}
But when I run on a remote server(Hive version: 0.13.1-SNAPSHOT). It throws the below mentioned error. I got to know that, the issue is with hive-jdbc, hadoop-core and hadoop-common versions. Can anyone let me know which versions of those dependencies I need to be using for Hive 0.13.1-SNAPSHOT
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
After a few trail and errors I fixed the version issue. The issue is hive-jdbc:2.1.0 is not backward compatible with Hive 0.13.1-SNAPSHOT, we need to use hive-jdbc:0.13.1 to make it work. Below code works with no doubt.
compile('org.apache.hadoop:hadoop-core:1.2.1')
compile ('org.apache.hive:hive-jdbc:0.13.1'){
exclude group: 'org.eclipse.jetty.aggregate', module: '*'
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j" }
compile ('org.apache.hadoop:hadoop-common:3.0.0'){
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}
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.