I need to execute a java class in a jar file. I tried as follows:
java -jar MyJar.jar
And got: no main manifest attribute, in MyJar.jar.
Then I realize that I must run a certain class which is in /directoryInsideJar/MyClass.class, but I don't have permission to edit MANIFEST.MF file. I found that I directly could theoretically run it by:
java -cp MyJar.jar firstdirectoryinpath.path.MyClass
But I got:
Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/Seq (...)
Caused by: java.lang.ClassNotFoundException: scala.collection.Seq
(...)
I'm pretty sure that the class exists and the path is correct.
What I'm doing wrong?
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 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?
I tried to run DependencyParserDemo.java in Stanford NLP parser.
I use Win7, jdk-10.0.1.
In command line:
Javac -cp stanford-parser.jar DependencyParserDemo.java
Works fine, DependencyParserDemo.class generated.
But when I run:
Java -cp stanford-parser.jar DependencyParserDemo
It shows:
Error: Could not find or load mian class DependencyParserDemo
Caused by: java.lang.ClassNotFoundException: DependencyParserDemo
Maybe the classpath setting is wrong?
You also need the location of the new class in your classpath.
Java -cp stanford-parser.jar;. DependencyParserDemo
I'm using the JDK 3.1. I am using XML Publisher. I'm getting this error:
Could not find the main class. Program will exit.
After I click on "OK", I get
Java execution failed. Please check the Java Option in the option dialog
Sounds like you're trying to execute .jar file and there's no Main-Class entry in the manifest file. Other than that obvious point, your question does not give much information for assistance.
Your question is tricky to understand, but I'm guessing that you haven't actually compiled your Java code, or your compiled code isn't on the classpath.
When I try and execute a non-existent class (this would work if there was a MyClass.class on the classpath with a main() method):
paul#paul-laptop:~$ java MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass
Caused by: java.lang.ClassNotFoundException: MyClass
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: MyClass. Program will exit.
Is that what you're seeing? If so:
compile your class with javac if you haven't done so
check that your classpath includes the location of the class
(You can specify the classpath explicitly when you execute the java program using -classpath, check the documentation for details.)
I include this answer as someone who has made an error someone consuming java rather than programming in it would make:
On the command line when executing a JAR file, be sure your line reads
java -jar whatever.jar
instead of
java whatever.jar
Without the -jar you sometimes get the "Could not find the main class" error.
Here are some good answers What does "Could not find or load main class" mean?
But, I will share one possibility I had. I used the JDK1.7 to compile my code and run the jar package using the JDK1.6, the error is:
Could not find the main class. Program will exit.
So, check if the JDK version you used to run your code is lower than that used to compile your code.
Check this website: "Could not find main class" error when previewing BI Publisher for Word. It directly references Java issues with Oracle BI Publisher Plugins for Word.
It basically says that you need to set your Java Home by going to Options in the BI Publisher Tab in the MS Office Ribbon.