You should use jar cfm myApp.jar manifest.txt *.class
to create the jar, so that the manifest file gets located correctly in the jar.
The right location of the manifest is META-INF/MANIFEST.MF
.
Update
I have made your code work, basically by taking the files you had prepared; adding a package declaration to the java files and the manifest, and upper-casing the MyApp class from myApp. The files are arranged in this folder structure:
tbsmac:17162802-executing-java-file-through-cmd tbsalling$ ls -lR
total 0
drwxr-xr-x 3 tbsalling staff 102 19 Jun 18:48 META-INF
drwxr-xr-x 4 tbsalling staff 136 19 Jun 18:57 thank
./META-INF:
total 8
-rw-r--r-- 1 tbsalling staff 46 19 Jun 18:49 MANIFEST.MF
./thank:
total 16
-rw-r--r-- 1 tbsalling staff 124 19 Jun 18:49 MyApp.java
-rw-r--r-- 1 tbsalling staff 98 19 Jun 18:48 T1.java
The contents of the three files are:
MyApp.java:
package thank;
class MyApp {
public static void main(String args[]) {
T1 t=new T1();
t.display();
}
}
T1.java:
package thank;
class T1 {
void display() {
System.out.println("Hey I am working");
}
}
MANIFEST.MF:
Main-Class: thank.MyApp
Manifest-Version: 1.0
Then I run this series of commands:
tbsmac:17162802-executing-java-file-through-cmd tbsalling$ javac thank/T1.java thank/MyApp.java
tbsmac:17162802-executing-java-file-through-cmd tbsalling$ jar cfm myApp.jar META-INF/MANIFEST.MF thank/*.class
tbsmac:17162802-executing-java-file-through-cmd tbsalling$ java -jar myApp.jar
Hey I am working
^^^ and it works ;-)