infinitezero
infinitezero

Reputation: 2077

Can't create executable jar file with Terminal

I try to create a simple executable jar file. My steps are:

Test.java

public class Test{
    public static void main(String[] args){
        System.out.println("Hello World");
    }
}

Terminal:

javac Test.java

produces Test.class

Checking:

java Test  
Hello World

creating a manifest.mf file:

Main-Class: Test

Then

jar -cfmv Test.jar manifest.mf Test.class   
added manifest  
adding: Test.class(in = 413) (out= 287)(deflated 30%)

Finally

java -jar Test.jar  
no main manifest attribute, in Test.jar

I followed all the steps from Katanas answer here: How to create a .jar file using the terminal

Update:

As adviced by ScaryWombat, I unzipped the jar file:

ls -alR  
.:  
total 16
drwxrwxr-x 3 infiniteZero infiniteZero 4096 May 28 02:25 .
drwxrwxr-x 4 infiniteZero infiniteZero 4096 May 28 02:26 ..
drwxrwxr-x 2 infiniteZero infiniteZero 4096 May 28 02:19 META-INF
-rw-rw-r-- 1 infiniteZero infiniteZero  413 May 28 01:50 Test.class

./META-INF:
total 12
drwxrwxr-x 2 infiniteZero infiniteZero 4096 May 28 02:19 .
drwxrwxr-x 3 infiniteZero infiniteZero 4096 May 28 02:25 ..
-rw-rw-r-- 1 infiniteZero infiniteZero   94 May 28 02:19 MANIFEST.MF

cat META-INF/MANIFEST.MF 
Manifest-Version: 1.0
Main-Class: Test.class
Created-By: 9-internal (Oracle Corporation)

Upvotes: 0

Views: 519

Answers (1)

user2208931
user2208931

Reputation:

add an empty line at the end of your manifest, recompile and run. And the manifest you are feeding the compiler hast to be in UTF-8

or:

  • open the jar location in total commander
  • click jar file and press Ctrl + PageDown
  • META-INF -> right click manifest and hit edit
  • add an empty line at the end of your manifest
  • save/exit and run java -jar Test.jar

Upvotes: 1

Related Questions