Posted by: jasonk2600 | November 12, 2008

Quickie HowTo: Running Java Programs from the Command Prompt

I hadn’t used any Java programs in a while, and remembered that Java programs come in byte-code and not in a directly executable format. So how do I run my Java programs from the command prompt? Here’s what I found after a quick look at the Java man page.

To execute a plain Java file, just pass the filename as a command line argument.

# java JavaProgram.java

To execute a program contained in a Java .JAR file, specify the -jar option, followed by the name of the .JAR file.

# java -jar JavaProgram.jar

Note to Linux users: If you’re running in a graphical environment and don’t want to be forced to have the terminal shell window open while using your Java program, simply add an ampersand (&) to the end of the command to detach the program from the terminal shell.

# java -jar JavaProgram.jar &

That’s it, that’s all there is to it.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Categories

%d bloggers like this: