Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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)

share|improve this question
3  
I couldn’t get your question. Do you mean a command to open a jar file? It’s java -jar path-to-file. –  AliNa Mar 7 '13 at 21:12
    
yeah Im trying to export a .jar file to the terminal line –  lightning Mar 7 '13 at 21:18
    
lightning@rigel5:~$ java /home/lighting/Documents/temp.jar Error: Could not find or load main class .home.lighting.Documents.temp.jar lightning@rigel5:~$ –  lightning Mar 7 '13 at 21:27
    
I exported the jar file to the documents folder and I am hoping to run it on the terminal line... its a 'hello world' –  lightning Mar 7 '13 at 21:28
    
at least I thought I did. how do I do that? –  lightning Mar 9 '13 at 0:10

3 Answers 3

up vote 3 down vote accepted

You can run java package using command java -jar MyFirstClass.jar on your terminal.

share|improve this answer
    
lightning@rigel5:~$ java -jar MyFirstClass.jar Error: Unable to access jarfile MyFirstClass.jar lightning@rigel5:~$ –  lightning Mar 8 '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 9 '13 at 4:25
    
Yep I sure do... Would love to solve this ...So how would I type that in the terminal? –  lightning Mar 9 '13 at 6:48
    
I had mispelled the classname in the manifest file. the classname is MyFirstClass not 'MyFirstCLass'. Oh, so embarrassed –  lightning Mar 9 '13 at 23:38

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.

share|improve this answer
    
'clearly' never sounded better. will have a look :D –  lightning Mar 7 '13 at 22:29
    
when I create the manifest file where do I put it? –  lightning Mar 7 '13 at 23:19
    
see the -m option for the jar command –  H.-Dirk Schmitt Mar 7 '13 at 23:21
    
See 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 8 '13 at 0: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 8 '13 at 23:49

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
share|improve this answer
    
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 8 '13 at 0: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 8 '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 9 '13 at 0:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.