JavaCoder
JavaCoder

Reputation: 3

Running Program

I'm currently using NetBeans IDE 7.4. When i (Clean and Build) my programs, they don't work unless there is a GUI. For example i have made 2 programs, a calculator and a click counter that had GUI and worked from the .java file. The simple "Hello World" program without a GUI and a number guessing game i made without GUI do not work from the .java file. The programs work completely fine in the IDE but after i (clean and build) the .java file of the projects do not even open. Does every program have to have a GUI? I thought programs like "Hello World" would be ran from the cmd by default. Thanks for the help!

Upvotes: 0

Views: 62

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168815

Does every program have to have a GUI?

No it doesn't. Apps. that have no GUI include:

  • Command line apps. and apps. intended to run on headless environments.
  • JEE apps. (though servlets and JSP and such do effectively create an HTML based GUI).

The programs work completely fine in the IDE but after i (clean and build) the .java file of the projects do not even open.

To get some output, run it from the command line using something like:

>java -jar the.jar

See the java command & the jar option for more info.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691635

When you double-click a jar file, the command that is actually run (which is associated with jar files) is javaw. javaw runs a Java program without opening a command line window. Double-clicking a jar file is indeed intended to run a GUI app.

If your program is a command line program, you should open a command line window, go to your dist folder, and execute

java -jar yourJarFile.jar

If you really want to have a double-clickable file that starts your command-line application, then provide a script (.sh/.bat) that runs the above command.

Upvotes: 1

Related Questions