1

I have a Java program that I have been working on. I would like to show it to my girlfriend, who would have no clue as to how to work with Java, and make it easy for her to do so. I understand the first step is to compile it to .class 's from the command line, but after that I am clueless.

I would be interested in finding out how to do this both for Windows and Mac OS (I am on a Mac, along with my girlfriend, but my school uses Windows computers).

I have been on Oracle and seen their demos, they download as .jnlp, is that a step in the right direction?

And specifically, I am looking for a "file" of some sort that is simply downloaded and launched, no terminal involved (maybe a file with a command line within?).

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Colin King
  • 83
  • 8

3 Answers3

6

Launching a Java program via double click
..seen .. demos, they download as .jnlp, is that a step in the right direction?

The title and that quote typically represent two different ways to launch Java desktop apps.

  1. "download as .jnlp" That is the 'deluxe' version, known as Java Web Start. It is a little trickier for the developer (you) but very easy for the user (your friend).
  2. "Launching a Java program via double click" is more commonly associated with an executable Jar. (Although JWS also supports the 'double click' - but with menus and shortcuts.)

Either strategy will work on OS X, Windows or *nix, but the first has JRE versioning (making sure the end user has a JRE, and it is recent enough to run the code) assisted by scripts, and many other 'bells and whistles'.

Java Web Start

  • JWS apps. typically deployed from a web page or server accessible to the user machine, so your friend 'surfs on over' to the link you sent her to 'Download here'.
    • The moment she arrives at your web page, the deployJava.js will check her PC has a suitable minimum version of Java to run the app. If not, she will be guided through a process to get it.
    • When the JRE is confirmed (which happens invisibly for those with a later JRE) the script writes a link in the web page that by default is a button.
      enter image description here
  • The user clicks the button and the JWS client (part of Java) will read the JNLP and begin to install the app.
  • If the app., requires permissions extended beyond the default sand-box, the user will be prompted as to whether to allow the code to run. See Appearance of Java Security dialog for more examples like:

    If the user chooses Run ..
  • The app. will be loaded and appear on-screen (possibly along with desktop shortcuts and start menu being added).
  • To launch it the second and subsequent times, the user double clicks the desktop shortcut or activates the menu item. This is how Starzoom (which has an icon defined in the JNLP) appears in Windows 7.
    enter image description here

Executable Jar

Another lesser alternative is an .

It uses a manifest.mf in the Jar that specifies the main class.

While being a lesser experience for the end user, it is also simpler for the developer - a trade off that might come in handy for limited distribution.

  • Requires a suitable version JRE installed.
  • The user obtains the Jar from whatever source (USB, Bluetooth, web site etc.) and saves it anywhere on their machine that is convenient.
  • To launch it, the user double clicks the Jar.
Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

You could create a bat script (Windows, I don't use OSX, but i think it's shell script for that) with the Java command you use to execute your Java program.

Or you could put you java class into a JAR file

lcguida
  • 3,787
  • 2
  • 33
  • 56
0

Try NetBeans, make a project in there, and build your codes with it. It automatically produce jar file that can be execute via double click almost in any platform.

oentoro
  • 740
  • 1
  • 11
  • 32