I have started using IntelliJ for my projects recently. I was trying to develop a simple maven project and got stuck into issue. I was trying to play around with kakfa-clients. Here is my dependencies
<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
I tried doing maven clean and install. I see the following error after I execute the code.
C:\KB\SDA>java -cp target/SDA-1.0-SNAPSHOT.jar org.example.code.Demo
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/kafka/clients/producer/Producer
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.clients.producer.Producer
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
However I could see the kafka-clients:2.5.0 is available in the External Libraries folder
I would like to know what could have gone wrong. Any hint would definitely help.
Java version 8
IntellJ 2020.1
Kafka-Client itself is dependent on other dependencies. Have a look here https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients/2.5.0
Give a shot by including other jars in the classpath.
java -cp target/*.jar:. org.example.code.Demo
Related
I am trying to get started with Drools 6x, and in eclipse, I have created a Drools project, which creates the boilerplate code to run a simple drl.
I have the drools runtime installed via Eclipse.
I have drools libraries, drools-core-5.0.1.jar,kie-api-6.0.0.beta4.jar,kie-internal-6.0.0.beta2.jar as External jars in my project.
Yet, when I try to run the following, I get the following error:
java.lang.ExceptionInInitializerError
at com.sample.PetStoreExample.init(PetStoreExample.java:78)
at com.sample.PetStoreExample.main(PetStoreExample.java:67) Caused by: java.lang.RuntimeException: Unable to instance KieServices
at org.kie.api.KieServices$Factory.<clinit>(KieServices.java:137)
... 1 more Caused by: java.lang.ClassNotFoundException:org.drools.compiler.kie.builder.impl.KieServicesImpl at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.kie.api.KieServices$Factory.<clinit>(KieServices.java:165)
... 1 more
If you downloaded the zip of Jars from http://www.drools.org/, you're going to want to include every jar from /binaries in your project. Even the ones that seem like you won't use.
I had this same problem too because I assumed I only needed to use a few Jars, but it turns out they all depend on classes from the other jars in that zip folder.
I had this problem because I had both kie-api and kie-ci as dependencies in my pom file. I removed the kie-ci dependency and I'm not getting this issue any more.
I'm trying to run the sample "Hello World" from the LWJGL website
From this link: LWJGL "Getting Started"
I'm trying to do this via the command line, just so I understand the "behind the scenes" a bit better.
I've managed to compile without any errors, but when I try to run the program I'm getting this error:
C:\JavaProjects\LearningLWJGL>java -classpath .;./lib/*.jar -Djava.library.path=C:\Windows\System32 HelloWorld
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFWKeyCallback
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFWKeyCallback
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Any ideas?
A CLASSPATH entry is either a directory at the head of a package hierarchy of .class files, or a .jar file. If you're expecting ./lib to include all the .jar files in that directory, it won't. You have to name them explicitly.
I had same issue using different dependancy what helped me is to set scope to compile.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
I am using Google + API to search for people using the following statement.
Plus plus = new Plus.Builder(httpTransport, jsonFactory, null).
setApplicationName("AppName").setGoogleClientRequestInitializer(new
PlusRequestInitializer(API_KEY)).build();
Plus.People.Search searchPeople = plus.people().search(personName).setMaxResults(1L);
PeopleFeed peopleFeed = searchPeople.execute();
I put the dependencies for the library in pom.xml so that it can be build when maven executed
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-plus</artifactId>
<version>v1-rev64-1.13.2-beta</version>
</dependency>
But I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/appengine/api/urlfetch/ResponseTooLargeException
at com.google.api.client.extensions.appengine.http.urlfetch.UrlFetchTransport.buildGetRequest(UrlFetchTransport.java:61)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:867)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:399)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:328)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:449)
at com.google.PeopleSearch.googleAccountSearch(PeopleSearch.java:52)
at com.google.Search.main(Search.java:128)
Caused by: java.lang.ClassNotFoundException: com.google.appengine.api.urlfetch.ResponseTooLargeException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Any suggestions?
I had a similar error NoClassDefFoundError: com/google/appengine/api/urlfetch/HTTPMethod , for me it was resolved by copying the App Engine SDK jar file from SDK/lib/user/appengine-api-1.0-sdk-1.9.27.jar into my project's WEB-INF/lib folder (I was not using Maven).
I used launch4j (http://launch4j.sourceforge.net/) software to create an executable of my application created in java netbeans.
I did everything as I saw in a tutorial, just that when I run the exectutavel it creates in my application, it gives this error:
The message shown below is:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
Does anyone can help me solve this problem please.
I've been searching but I can not solve. I apologize for this question but am new to java.
Thank you all.
Greetings
In your launch4j configuration file add the jars like this
<classPath mainClass="your.main.class">
<cp>path/to/javamail.jar</cp>
<cp>path/to/folder/*.jar</cp> // you can also add all the jars in a folder like this
</classPath>
It will automatically bundle them.
Hope this helps
EDIT
Just went through netbeans integration with launch4j and it seems there is no way to write your on config xml file instead it prompts you in launch4J GUI for dependencies. I searched and found this Stackoverflow Post. This is what you want. Good Luck.
Add Java mail jar to classpath.
Download it from here
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eeplat-419426.html#javamail-1.4.7-oth-JPR
I have tried a spring(3.1.0) project for the first time,but it gives me runtime errors.I have added log4j but still error occurs.and the org.springframework.beans.factory.xml.XmlBeanFactory is deprecated too.
please help me
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:83)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.<init>(FactoryBeanRegistrySupport.java:43)
at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:175)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:157)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:168)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:158)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:77)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:66)
at com.vehicle.SpringDemoApp.main(SpringDemoApp.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 9 more<br/>
this is what i got
You need apache commons-logging in the classpath. Log4j is not commons-logging.
download commons logging jar from
http://commons.apache.org/logging/download_logging.cgi
You can check which class is in which Opensource (OSS) library here.
If you are using Maven, you can try adding the following dependency:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<classifier>api</classifier>
</dependency>