0

I've written a few java applications (desktop, no browser involved) for friends, some of whom are less technical than I am. They use Windows, Linux and Macs. Originally I just used javac to generate bunches of .class files, zipped it all up and had them unpack it all. It works, but they had to install the JRE (terrifying for some), write a script to run java or javaw followed by command line args, app name, more arguments (incomprehensible for some), mark the script executable... I got mocked, somewhat rightfully, for a geek solution. They wanted to download from a website, doubleclick and be up and running.

I thought creating a .jar file would be the solution. It didn't help. In Eclipse, the options seem to be "create a jar file", which lets me include the handful of resources (.png files mostly) the apps needs, but the result isn't runnable from a command line. Or, create an executable .jar file, which doesn't seem (at least from Eclipse) to have a way to include resources - and the resulting .jar file doesn't start when double-clicked, even when I set the execute bit, even though the default run environment points to the Java suit. Even with a .jar file, I'm stuck with having them script "java -jar App...", and that's pretty much a dealbreaker.

I'm missing something. The point of Java is platform independence. Is there a platform independent way to have them download a single file, double click it and have it off and running?

Scott M
  • 684
  • 7
  • 14

1 Answers1

0

If you are trying to create a runnable jar file from your project in Eclipse, you have to select that option when exporting. You can do this by Export > Java > Runnable Jar File. If you only select the Jar File option, you won't be able to run it.

If you want to wrap your application as a .exe, you can use launch4j. Here's a thread that explains it a little more and has some other options.

parthlr
  • 386
  • 3
  • 13
  • Thanks, but the runnable jar file option doesn't seem to offer to pick up resources like .png files, so it's not a one-downloadable-file solution. launch4j looks interesting; thanks. – Scott M May 20 '20 at 00:45
  • 1
    launch4j seems to be a windows-only solution. – Scott M May 20 '20 at 03:40
  • @ScottM You could try creating a `resources` folder in your `src` folder and add your images to that folder. That way you can package it into your runnable jar file. [More info](https://www.cefns.nau.edu/~edo/Classes/CS477_WWW/Docs/pack_resources_in_jar.html) – parthlr May 21 '20 at 17:33