Java Eclipse ClassNotFoundException after importing external JARs - java

I'm getting a ClassNotFoundException when I try to execute the following code:
import org.apache.commons.text.WordUtils;
public class CapitalizeFirstLetters {
public static void main(String[] args) {
String str="this is a test";
str=WordUtils.capitalizeFully(str);
System.out.println(str);
}
}
I'm new to importing libraries in Java. Here is what my Package Explorer and Build Path look like (I closely followed advice from other people asking similar questions).
Project Explorer ,
Java Build Path
and here is the error text:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at org.apache.commons.text.WordUtils.capitalizeFully(WordUtils.java:494)
at org.apache.commons.text.WordUtils.capitalizeFully(WordUtils.java:464)
at CapitalizeFirstLetters.main(CapitalizeFirstLetters.java:7)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
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)
... 3 more
Can anyone please help me with this? I cannot find the answer for this problem in Eclipse anywhere online. So far I have tried: deleting everything and starting over.
Thank you!

Related

Eclipse: export java library with dependencies

I am trying to export a java library in eclipse that has other dependencies - namely apache commons-io. I was able to export it by going to Export >> Jar File - making sure that the libraries are ticked in the "Select the resources to export" box. However, when I implement the library into a test class and run it; I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
at com.jwf.JavaWebFramework.main.PageBuilder.copyInputFiles(PageBuilder.java:135)
at com.jwf.JavaWebFramework.main.PageBuilder.build(PageBuilder.java:44)
at com.jwf.JavaWebFramework.main.JWF.init(JWF.java:18)
at com.jwf.JWFTest.JWFTest2Main.main(JWFTest2Main.java:23)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
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)
... 4 more
For whatever reason, Eclipse doesn't appear to be finding the FileUtils class.
Any advice would be greatly appreciated.
Cheers!

ListValuedMap NoClassDefFoundError when Reading Excel using Apache Poi?

While Executing the Program, Below are the issues Compiler is throwing
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/collections4/ListValuedMap
at ReadExcel.main(ReadExcel.java:19)
Caused by: java.lang.ClassNotFoundException:
org.apache.commons.collections4.ListValuedMap
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)
... 1 more
Please help me know how to solve this
Thanks in advance
you should be good if you add the below jar.
https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.1
You are missing some required class maybe check your version on pom.xml if you are using eclipse you can do cnt shift T and see if you can open the missing class (ListValuedMap)file and see if it comes from the same jar as you specified in your pom.

Can not get an Output file in Stanford NER

I'm new to Stanford NER and have some problems.
I have downloaded Stanford Named Entity Recognizer version 3.6.0. It works, no problem. But I can't get a tagged text as an output file. Read about extracting data on this site: http://www.themacroscope.org/2.0/using-the-stanford-named-entity-recognizer-to-extract-data-from-texts (Windows user).
Tried to do the same, but got a few errors in command line:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFacto
ry
at edu.stanford.nlp.io.IOUtils.<clinit>(IOUtils.java:42)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(Abstrac
tSequenceClassifier.java:1484)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifierNoExcept
ions(AbstractSequenceClassifier.java:1497)
at edu.stanford.nlp.ie.crf.CRFClassifier.main(CRFClassifier.java:3015)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 4 more
Can somebody explain what's wrong and how should I correct it?
Thank you!
You need to include the lib folder in your CLASSPATH. It contains the necessary jars.
Your program is missing a logger dependency (or somehow it's being blocked by another dependency). I'd try adding it manually:
http://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.7.21
Side note: you can also give a try to illinois-NER.

error while running main function without libgdx

I have been using libGdx for a while now. I have created a new project without using libGdx and created some class trying to practice some code if it works as I intended. However, I'm getting error that main class is not found in the libgdx package.
How Do I switch between libgdx and just native IDE.
So for example...
package com.example.example;
public class Example
{
public static void main (String[] args)
{
System.out.println("hey");
}
}
when i try to run this code I get error
Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/jnigen/BuildTarget$TargetOs
at com.badlogic.gdx.physics.box2d.utils.Box2DBuild.main(Box2DBuild.java:13)
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.jnigen.BuildTarget$TargetOs
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)
... 1 more
How do I fix this? Thanks in advance!
I ran into this error today and Lestat was correct.
In your IDE (in my case Eclipse): go to Run> Run As> Java application.

XUGGLE ERROR: Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

I am trying to execute the following code:
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
public class vidcon {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
IMediaReader reader = ToolFactory.makeReader("test.m4v");
IMediaWriter writer = ToolFactory.makeWriter("out.flv");
reader.addListener(writer);
while(reader.readPacket() == null)
;
}
}
But it is is giving me this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.xuggle.ferry.JNILibrary.<clinit>(JNILibrary.java:42)
at com.xuggle.ferry.FerryJNI.<clinit>(FerryJNI.java:14)
at com.xuggle.ferry.Ferry.<clinit>(Ferry.java:25)
at com.xuggle.xuggler.XugglerJNI.<clinit>(XugglerJNI.java:19)
at com.xuggle.xuggler.IContainer.<clinit>(IContainer.java:1622)
at com.xuggle.mediatool.MediaReader.<init>(MediaReader.java:137)
at com.xuggle.mediatool.ToolFactory.makeReader(ToolFactory.java:77)
at vidcon.main(vidcon.java:11)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 8 more
I have added SLF4J to my referenced libraries, but have no idea why this is not working.
Running on WIN 7, tried in eclipse and netbeans
Any idea?
Download SLF4J and put the slf4j-api-1.7.2.jar file onto your class path.
The following combination of jars is working for me:
log4j-1.2.16.jar
slf4j-api-1.7.6.jar
slf4j-simple-1.7.6.jar
xuggle-xuggler-5.4.jar
Cause Could be un-availability of dependency jars or version conflicts.
The following jars combination worked fine for me:
xuggle-xuggler-5.4.jar
slf4j-api-1.6.4.jar
logback-core-1.0.0.jar
logback-classic-1.0.0.jar
you might be added the apache-log4j-2.7-bin jars.
Just Remove all those Jars and keep only
log4j-1.2.16.jar
slf4j-api-1.7.6.jar
slf4j-simple-1.7.6.jar
xuggle-xuggler-5.4.jar
Download SLF4J and put the slf4j-api-1.7.25.jar, slf4j-simple-1.7.25.jar files into application class path.
This will help to resolve this exception along with following exception SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
Check your configuration file (.xml file). The first line in this must start with the declaration of XML version and encoding.
Otherwise, you will get the same error util unless you have included all the required .jar files.

Categories