This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes running with command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "running with command line" Watch "running with command line" New topic

running with command line

bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
hi all,

i know this sounds really newbie. but how do i run my swing application on a command line?
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

What kind of OS that do you use?

firstly, you have to set path all of the libraries that you need..

Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37936
java MySwingClassWithMainMethod "Frame Title"
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167

From the command line you can run it like
java MyMainClass where MyMainClass is the one with the main method.

If you got a self executing jar file (where the manifest file includes the Main class entry) you can run it like
java -jar MySwingApp.jar

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
i got this :

what is wrong ? is it because of the library? how do i add the library specifically?

Joanne Neal

Joined: Aug 05, 2005
Posts: 3419
You run .class files, not .java files and you don't need the extension
java Noose_Machine

bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
i see... that's very noob of me. really sorry about it.

i have another question. i have around seven external libraries which means i have to add in a long list of jar into the command line..

is there a solution to that? like combining them all into a single jar? how do i do that?
Joanne Neal

Joined: Aug 05, 2005
Posts: 3419
If you're using Java 1.5 or later you can put all the jars into a directory and then use a wild card in your classpath
java -cp <path to myjardirectory>\* Noose_Machine

Note that the wild card is * and not *.jar

Alternatively, when you start writing more complex applications, you can combine all your class files into a jar file and then specify a list of all the required jars in the manifest file for your jar file. You then run your program with the java -jar command. There are plenty examples of this on these forums
I agree. Here's the link:
subject: running with command line
Similar Threads
Compiler error!
Which SVN client for Linux
How can that possible compile???
How to run remote command from a JSP