JAVA – HELLWORLD using Command line

I was following this tutorial, trying to understand how the build process works for Java. I first ran the hellworld example and then package the program into a jar file purely using command line.

First, here are a few arguments in command javac and jar that will be used.

Usage: javac <options> <source files>
-sourcepath <path>     Specify where to find input source files
-d <directory>         Specify where to place generate class files
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ... 
-c create new archive
-f specify archive filename
-m include manifest information from specified manifest file
-C change to the specified directory and include the following file
(The . following -C images directs the Jar tool to archive all the contents of that directory)

# compile
javac -sourcepath src/ -d build/classes/ src/datafireball/HelloWorld.java
# package
jar cfm build/jar/HelloWorld.jar myManifest -C build/classes/ .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s