java.lang.NoClassDefFoundError | - java

My java program is running fine on my Eclipse IDE, but when am trying to run the same ".java" file using my command prompt it is showing me an error as shown in the fig.
Error: Could not find or load main class EulerianPathDirectedEdgesAdjacencyList
Caused by: java.lang.NoClassDefFoundError: com/euler/EulerianPathDirectedEdgesAdjacencyList (wrong name: EulerianPathDirectedEdgesAdjacencyList)
While am running the same code in my Eclipse IDE its working fine!
Please let me know, how to solve this.
Thanks!

Try running the command : java com.euler.EulerianPathDirectedEdgesAdjacencyList from the same directory where class file got created after running the previous javac command

Related

Keycloak server problem Could not find or load main class

I can't run keycloak server, when I try to run kc.bat in windows powershell or cmd with
.\kc.bat
I get the error
Error: Could not find or load main class io.quarkus.bootstrap.runner.QuarkusEntryPoint
Caused by: java.lang.ClassNotFoundException: io.quarkus.bootstrap.runner.QuarkusEntryPoint
I installed quarkus but it doesn't work even tho I installed it
There is an open bug related to this issue.
You have to edit kc.bat line 127 replace : with ;

how to run a java file from a parent directory?

I am able to compile a java file that is inside a directory by using javac <directory_name>/Solution.java.
but I am not able to run the java program in the same manner ie. java /Solution.
as it gives me this error :
Error: Could not find or load main class code.Solution Caused by:
java.lang.NoClassDefFoundError: Solution (wrong name: code/Solution)
Here code is my directory name.
I could cd into the directory and do it. which actually works but that is not the behavior that I desire.
How to achieve this?

Error while running mapreduce program in eclipse juno

I am using cdh4 and eclipse juno
While running the wordcount program I met with this error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
I have already installed commons-lang3-3.1 jar file
You are importing wrong class. From 3 on, the package is org.apache.commons.lang3 not org.apache.commons.lang. You need to either use commons-lang-2*.jar or import proper class.

How to get the buildindex step working in the semanticvectors java package on a mac OS X terminal?

I'm trying to use semantic vectors. Here are some links:
https://code.google.com/p/semanticvectors/wiki/InstallationInstructions
https://code.google.com/p/semanticvectors/
Anyway, I'm on the step where you input java pitt.search.semanticvectors.BuildIndex, but I'm lacking results.
The current part I'm following is "To Build and Search a Model".
I am able to compile the package successfully with the ant command and I did get the first step working with first setting the class path with:
export CLASSPATH=./lib/lucene-core-3.6.2.jar:./…
And then inputing
java org.apache.lucene.demo.IndexFiles -docs .
However with this next step I'm getting these errors:
user:/home/data/SemanticVectors/semant… java pitt.search.semanticvectors.BuildIndex
Exception in thread "main" java.lang.NoClassDefFoundError: pitt/search/semanticvectors/BuildIndex
Caused by: java.lang.ClassNotFoundException: pitt.search.semanticvectors.BuildIndex
at java.net.URLClassLoader$1.run(URLClassLo…
at java.security.AccessController.doPrivile… Method)
at java.net.URLClassLoader.findClass(URLCla…
at java.lang.ClassLoader.loadClass(ClassLoa…
at sun.misc.Launcher$AppClassLoader.loadCla…
at java.lang.ClassLoader.loadClass(ClassLoa…
Could not find the main class: pitt.search.semanticvectors.BuildIndex. Program will exit.
I am using a terminal on a mac OS X
As I see your post, it appears you are not providing a path to the semanticvectors-x.x.jar file as indicated in
export CLASSPATH=./lib/lucene-core-3.6.2.jar:./…
Once this change is done, it should work.

Why can't I compile my Java applications using Ubuntu?

I have been trying for what seems like two days now to get my java application to compile from the command line in Ubuntu. I know I have Java installed because I can run my applications in Eclipse & Netbeans and they work fine. But if I want to compile my applications from the command line I get the following error message:
javac Main.java
Everythings fine, no errors or anything. Then I try:
java Main
And I get this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name: input/Main)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:637)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
Could not find the main class: Main. Program will exit.
Try:
java input.Main
By the looks of your error, your Main class is in package "input". You need to specify package name when running a class, not the filename.
Open terminal and paste this command:
export CLASSPATH=.:/usr/local/tomcat/common/lib/jsp-api.jar:/usr/local/tomcat/common/lib/servlet-api.jar:/home/trenog/javokapi/bin/xmlrpc.jar
This looks like a classic Classpath problem. Eclipse and Netbeans will set up the classpath for you, but when you're writing to the command line, you're on your own.
Assuming you're using BASH, try typing the following into the command line:
CLASSPATH=/path/to/your/java/class/file
Or, alternately, you can do this from the java command line:
java -cp /path/to/your/java/class/file Main
Follow this link for more info.
EDIT: Well, I see you figured it out. Congrats.
The classloader simply can't find the class input.Main.
The class should be located in the directory ./input, the file inside that directory should be called Main.class and the java command should be 'java input.Main'.

Categories

Resources