no main manifest attribute, when trying to run a jar file - java

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

Related

Execute certain java class which is not main class of a jar file from linux

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?

java.lang.NoClassDefFoundError |

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

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?

Java: In command line, Could not find or load main class

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

could not find the main class

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.

Categories

Resources