Wednesday, 27 November 2013

Java - Create JAR within Terminal

Java - Create JAR within Terminal

So Myself and Kevin created a class file today and we wanted to create a Jar file using Terminal.

What we did to do this, is we used Terminal.

The short: If you want to create a Jar File:
jar cfe Main.jar Main Main.class

c: create File
f: File
e: Entry Point: The main method

The Format is
jar cfe <Jar File to create> <Class with main method> <classes to include>
You can also use
jar cfe Main.jar Main *.class


So what we initially did was we created the jar file with the "Default Manifest File" which looked like :
Manifest-Version: 1.0
Created-By: 1.7.0_25 (Oracle Corporation)

As you can see this is missing the Main-Class pointer.

So then we did some more research and found we needed to include the Entry Point, our main method.

Manifest-Version: 1.0
Created-By: 1.7.0_25 (Oracle Corporation)
Main-Class: Main

Our Java code looked like:

public class Main{

 public Main(){
  System.out.println("Main");
 }
public static void main(String[] args){
  System.out.println("Main method");
  new Main();
 }


#bearMan and theStroud

No comments:

Post a Comment