반응형

아래의 코드를 가지고 실행가능한 JAR 파일을 만든다고 가정합니다.

public class HelloApp {

 private String name = "";
 public HelloApp(String name) {
 this.name = name;
}

public void sayHello() {
 System.out.println("Hello, my name is " + name + ".");
 }

 public static void main(String[] args) {
  HelloApp app;
  if (args.length > 0)
   app = new HelloApp(args[0]);
  else
   app = new HelloApp("RESISA~");
  app.sayHello();
 }
}

아래의 순서에 따라 만들면 됩니다.. ^_^;

1. Compile:

Prompt> javac HelloApp.java

2. Make a menifest file "MANIFEST.MF".

Prompt> mkdir META-INF
Prompt> edit META-INF\MANIFEST.MF

[Remark]
MENIFEST.MF must contain at least the following line.
Main-Class: HelloApp

3. Create a jar file "hello.jar" by using such a command
jar cmf {manifest file} {jar file} {class files}

Prompt> jar cmf "META-INF\MANIFEST.MF" hello.jar HelloApp.class

4. Execute:

Prompt> java -jar hello.jar
Prompt> java -jar hello.jar "Duke Java!"

+ Recent posts