I have an application which is working fine until I have introduced the following maven dependencies.
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>commons-compiler-jdk</artifactId>
<version>3.0.0</version>
</dependency>
After introducing the following dependencies, the jar is getting built properly, no compiler exceptions but when running the application, it is failing with the following exceptions:
Exception 1:
Exception in thread "2/streamJsonParser:StreamingJsonParser" java.lang.NoClassDefFoundError: org/apache/log4j/spi/ThrowableInformation
at org.apache.log4j.spi.LoggingEvent.<init>(LoggingEvent.java:165)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.log(Category.java:856)
at org.slf4j.impl.Log4jLoggerAdapter.error(Log4jLoggerAdapter.java:540)
at com.datatorrent.stram.engine.StreamingContainer$2.run(StreamingContainer.java:1431)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.spi.ThrowableInformation
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 5 more
Exception 2:
Exception in thread "org.apache.hadoop.hdfs.PeerCache#3826c025" java.lang.NoClassDefFoundError: com/google/common/collect/LinkedListMultimap$3
at com.google.common.collect.LinkedListMultimap.values(LinkedListMultimap.java:846)
at org.apache.hadoop.hdfs.PeerCache.clear(PeerCache.java:271)
at org.apache.hadoop.hdfs.PeerCache$1.run(PeerCache.java:128)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.LinkedListMultimap$3
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
Exception 3:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/helpers/NullEnumeration
at org.apache.log4j.Category.getAllAppenders(Category.java:413)
at org.apache.log4j.Category.closeNestedAppenders(Category.java:226)
at org.apache.log4j.Hierarchy.shutdown(Hierarchy.java:467)
at org.apache.log4j.LogManager.shutdown(LogManager.java:267)
at com.datatorrent.stram.engine.StreamingContainer.main(StreamingContainer.java:332)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.helpers.NullEnumeration
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 5 morexception in thread "Thread-3" java.lang.NoClassDefFoundError: org/apache/hadoop/util/ShutdownHookManager$2
at org.apache.hadoop.util.ShutdownHookManager.getShutdownHooksInOrder(ShutdownHookManager.java:124)
at org.apache.hadoop.util.ShutdownHookManager$1.run(ShutdownHookManager.java:52)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.ShutdownHookManager$2
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
Please let me know what needs to be done. I have tried adding some as well but didn't work. Please suggest.
Include following dependencies in your POM
<!-- https://mvnrepository.com/artifact/log4j/apache-log4j-extras -->
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
These are missing and because of that you're getting exception.
Following is the screenshot of the POM Editor dependencies tab in STS. Latest eclipse should also have it.
You can also use following command to check dependencies.
mvn dependency:tree
Did you try this :
mvn clean install -U
The -U ask maven to force update of dependencies.
I accepted the answer above as the user has explained me a way to identify the duplicate dependencies getting added.
It is actually an issue with duplicate hadoop dependencies from the POM and the run time environment.
Related
I am trying to follow the Documentation of Elastic Search to get and post data from it using its java Api's. But i am constantly getting error.
This is the code i have tried as of now.
Settings settings = Settings.builder().put("twitter", "tweet").build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
GetResponse response = client.prepareGet("twitter", "tweet", "1").get();
The stack trace
Exception in thread "main" java.lang.NoClassDefFoundError:
com/google/common/collect/ImmutableSortedMap
at com.c1x.entity.Test.main(Test.java:20)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableSortedMap
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Please Help , i am new to Elastic search , the data is present in elastic search as i can see it when i use dev tools in kibana
after adding google commons
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/SetOnce
at org.elasticsearch.common.settings.Settings$Builder.<init>(Settings.java:676)
at org.elasticsearch.common.settings.Settings$Builder.<clinit>(Settings.java:671)
at org.elasticsearch.common.settings.Settings.<clinit>(Settings.java:84)
at com.c1x.entity.Test.main(Test.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.SetOnce
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
After adding lucene jar
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at org.elasticsearch.common.Strings.<clinit>(Strings.java:459)
at org.elasticsearch.common.settings.Settings.<init>(Settings.java:90)
at org.elasticsearch.common.settings.Settings$Builder.build(Settings.java:1215)
at com.c1x.entity.Test.main(Test.java:21)
Another error
Exception in thread "main" java.lang.VerifyError: class org.elasticsearch.transport.Netty3Plugin overrides final method onModule.(Lorg/elasticsearch/common/network/NetworkModule;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<clinit>(PreBuiltTransportClient.java:84)
at com.c1x.entity.Test.main(Test.java:22)
You miss the google-collections.jar in your classpath. Add it and the error will go away.
If you are using maven as dependency Management tool, add the follwing lines to your pom.xml:
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
Next jar is missing add lucene-core-<version>.jar
maven dependency is:
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>6.5.1</version>
</dependency>
I am getting error :
javax.xml.bind.JAXBException
- with linked exception: [java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory] at
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:195) at
javax.xml.bind.ContextFinder.find(ContextFinder.java:381) at
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574) at
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522) at
com.zhongway.jtjk.cutoverinfo.CutOverInforequest.getCutOVERinfoxml(CutOverInforequest.java:29)
at
com.zhongway.jtjk.cutoverinfo.CutOverInforequest.main(CutOverInforequest.java:247)
Caused by: java.lang.ClassNotFoundException:
com.sun.xml.bind.v2.ContextFactory at
java.net.URLClassLoader$1.run(URLClassLoader.java:200) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:188) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) at
java.lang.ClassLoader.loadClass(ClassLoader.java:251) at
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:191) ...
5 more
I have added following jars:
javax.xml.bind-2.0.jar jaxb-2.0-m13-1.jar jaxb-api-2.0-ea3.jar
Can someone help me out what wrong with this code.
Add Below dependecy in your pom.xml file.
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
File | Settings | Build, Execution, Deployment | Build Tools | Gradle
Change gradle jdk
I am new to Spring-boot and trying to encrypt password in application.properties file using jasypt library. I used #EnableEncryptableProperties with #SpringBootApplication and getting error. Don't know how to get its resolution. Following is the dependency used in my pom.xml. I am using JDK 7 to build this Application. If you know any other framework to encrypt password in properties it will be appreciated.
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot</artifactId>
<version>1.2</version>
</dependency>
My main class is :
#SpringBootApplication
#EnableSwagger2
#EnableJSONDoc
#EnableAsync
#EnableEncryptableProperties
public class App extends SpringBootServletInitializer{
...
}
And i am getting following exception:
java.lang.UnsupportedClassVersionError: com/ulisesbocchio/jasyptspringboot/annotation/EnableEncryptableProperties : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:432)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:238)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:117)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3271)
at java.lang.Class.getDeclaredAnnotations(Class.java:3248)
The messages tells you that the class-file which should be loaded was compiled for java 8. So you need a JDK8 to use the "com.github.ulisesbocchio/jasypt-spring-boot" library.
You can have a look at spring cloud. It supports encrypted properties and only needs java 7 (afaik)
I'm trying to use a Mashape api, I have added the following libraries (jars) unirest, httpasyncclient, httpclient, httpmime, org.json, commons-longging, httpcore to my project.
I'm trying to run...
HttpResponse<JsonNode> response = Unirest.post("https://life-left.p.mashape.com/time-left")
.header("X-Mashape-Key", "1NZITOdDGqmshKRAEdDbX0tp0WV2p1RR5SSjsnQYQIVwrANkhC")
.header("Content-Type", "application/x-www-form-urlencoded")
.field("birth", "22 April 1977")
.field("gender", "female")
.asJson();
But I get this exception...
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/nio/reactor/IOReactorException
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:154)
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:131)
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
at test.Test.main(Test.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.nio.reactor.IOReactorException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
I've tried googling around but I can't find out what is wrong.
Any help would be appreciated.
I had same problem but resolved after adding following dependency in my project pom.xml file
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.4.3</version>
</dependency>
I am trying the example from following site
http://www.mkyong.com/spring/spring-quartz-scheduler-example/
I have added junit to fix build error but getting the following error...any help is appreciated
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext
at com.mkyong.common.App.main(App.java:7)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.support.ClassPathXmlApplicationContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Add spring-context-support.jar and spring-context.jar in your application path and then run application