1

Mispelled classname in manifest.txt file caused this error

enter image description hereenter image description hereIm trying to run a java file outside of my IDE by exporting the .jar file to my documents folder and trying to display the text 'hello world'in the file on the terminal line. I attempted to create a Manifest.txt file with this in it,

Main-Class: lightning.java.hello.MyFirstClass

I then used this script to create a file MyJar.jar and got this back,

lightning@rigel5:~$ jar cfm MyJar.jar Manifest.txt lightning.java.hello/*.class java.io.FileNotFoundException: Manifest.txt (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:138) at java.io.FileInputStream.(FileInputStream.java:97) at sun.tools.jar.Main.run(Main.java:171) at sun.tools.jar.Main.main(Main.java:1177)

Alvar
  • 17,058
lightning
  • 643

3 Answers3

3

You can run java package using this command on your terminal:

java -jar MyFirstClass.jar

If you don't have Java Runtime Edition (JRE) you'll need to install default-jre package.

Pablo Bianchi
  • 15,657
  • lightning@rigel5:~$ java -jar MyFirstClass.jar Error: Unable to access jarfile MyFirstClass.jar lightning@rigel5:~$ – lightning Mar 08 '13 at 22:18
  • it seems you are on the wrong path, because it can not find the jar file. make sure you are in the jar file directory when using the command. – Muhammad Sholihin Mar 09 '13 at 04:25
  • Yep I sure do... Would love to solve this ...So how would I type that in the terminal? – lightning Mar 09 '13 at 06:48
  • I had mispelled the classname in the manifest file. the classname is MyFirstClass not 'MyFirstCLass'. Oh, so embarrassed – lightning Mar 09 '13 at 23:38
2

java /home/lighting/Documents/temp.jar Error: Could not find or load main class .home.lighting.Documents.temp.jar lightning

This shows that you clearly have done a mistake in the META-INF/MANIFEST.MF

See this Tutorial for more informations.

  • 'clearly' never sounded better. will have a look :D – lightning Mar 07 '13 at 22:29
  • when I create the manifest file where do I put it? – lightning Mar 07 '13 at 23:19
  • see the -m option for the jar command – H.-Dirk Schmitt Mar 07 '13 at 23:21
  • See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details. lightning@rigel5:~$ java -cp temp.jar MyFirstClass.lightning.java.hello Error: Could not find or load main class MyFirstClass.lightning.java.hello lightning@rigel5:~$ – lightning Mar 08 '13 at 00:49
  • this is my MANIFEST.MN file;Manifest-Version: 1.0 Class-Path: . Main-Class: lightning.java.hello.MyFirstClass I created a file Manifest.txt and it looks like this;MainClass: lightning.java.hello.MyFirstCLass – lightning Mar 08 '13 at 23:49
2

First you need a main-method in your class file - public static void main(String args[]){ ... } - probably done...

In the jar-file you need a manifest.txt file - inside the class with the main method has to be noted like this -> Main-Class: MyPackage.MyClass

To create one you can use the commandline tool jar ...

If you don't have an manifest-file in your jar, you can just type:

java -cp jarFileName.jar ClassNameWithMainMethod
Eric Carvalho
  • 54,385
  • lightning@rigel5:~$ java -cp temp.jar.lightning.java.hello.MyFirstClass I typed this in and got a java command usage index and did not display the file – lightning Mar 08 '13 at 00:43
  • @lightning you have a dot between the jar name and the classname in your command. Could this be the reason for it to be failing? – elias Mar 08 '13 at 21:02
  • lightning@rigel5:~$ java -jar MyFirstClass.jar Error: Unable to access jarfile MyFirstClass.jar lightning@rigel5:~$ temp.jar lightning.java.hello.MyFirstClass temp.jar: command not found – lightning Mar 09 '13 at 00:07