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?
Related
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
I'm trying to run this Java GUI application but I'm not sure how to get it to run. The project is located here: https://gitee.com/gangshushu/v7/tree/master/admon_gui/one-jar.
My initial attempt was:
java -jar one-jar-ant-task-0.97.jar
But I end up with the error:
no main manifest attribute, in one-jar-ant-task-0.97.jar
Doing some search around, Failing to run jar file from command line: “no main manifest attribute”, I ended up running:
java -cp one-jar-ant-task-0.97.jar Main
But I end up with another error message:
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
Searching around gave me some information overload here: What does "Could not find or load main class" mean?
How do I run this Java program? This is my first time trying to run a jar file, and I'm a little stuck.
Am I trying to run the Java program the wrong way?
Your main class is in a package, you need to specify in what package to find your main class. Try the following command line:
java -cp one-jar-ant-task-0.97.jar com.beegfs.admon.gui.program.Main
I'm new to Java and have a program that's throwing the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper
at ExtractCustomerIds.main(ExtractCustomerIds.java:21)
Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapper
at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base#9-internal/BuiltinClassLoader.java:366)
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base#9-internal/ClassLoaders.java:184)
at java.lang.ClassLoader.loadClass(java.base#9-internal/ClassLoader.java:419)
... 1 more
I know the problem has to be with paths, classpath or jar name, but I can't figure out as of now.
My folder structure is:
.
- get_customer_ids
- ExtractCustomerIds.java
- libs
- jackson-all-1.9.11.jar
So when I'm inside the get_customer_ids I give the following command:
get_customer_ids$ javac -cp ../libs/* ExtractCustomerIds.java and this causes the error above.
I thought I was setting the classpath correctly, but it's still not working. What's missing?
The exception occurs when running your program - you are specifying the classpath while compiling. The classpath set during compilation is not stored inside the compiled class files or the like - you need to correctly specify it when running your program, too!
Like so:
$ java -cp ../libs/* ExtractCustomerIds
running a java class by shell script:
java -cp $CLASSPATH CG_GpsRequest "dbname","oracle.jdbc.driver.OracleDriver","abc","abc"
while running the script in unix, getting error,
Exception in thread "main" java.lang.NoClassDefFoundError: CG_GpsRequest
Caused by: java.lang.ClassNotFoundException:
CG_GpsRequest is the class file name.
Okay.. If I understand you correctly..
I think its problem with the Package name specification..
Your calss CG_GpsRequest you must have specified in Packaging way for example
com.xxx.yyy.CG_GpsRequest
So I think JVM is searching your class com.xxx.yyy.CG_GpsRequest in this patter so Please run your script with the following modifications.
java -cp $CLASSPATH com.xxx.yyy.CG_GpsRequest "dbname","oracle.jdbc.driver.OracleDriver","abc","abc"
This is just assumption that you have created your class in Pacakgin hirarechy since you havent specified more information.
Add the folder/path in which your java class exists to your CLASSPATH
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.