Sunday, December 22, 2013

Simple steps to generate and run jar

It is simple steps to generate hello.jar from hello.java (with main() method) using javac and jar, then run the jar using java.
Simple steps to generate and run jar
Simple steps to generate and run jar
  • Compile with javac to generate class file:

    javac hello.java
  • Generate jar file using jar:

    jar cf hello.jar hello.class

    option c - create a JAR file.
    option f - output to a file.
    hello.jar is the output file name
    last argument(s) can be more than one file that you want to include in your JAR file.
  • Run the jar using java:

    java -cf hello.jar hello

    -cf specify the classpath of hello.jar.
    hello is the class contains the main method.

No comments:

Post a Comment