• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAR / JRE question  RSS feed

 
Sam Smoot
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can create a .jar file for my project, but I want to make it executable and include the "correct" JRE so that I don't have to worry about what is on the user's machine..
Any way to do this so that all I have to do is distribute the .jar file?
Thanks!
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can include the whole jre in the jar-file, but, what a pity, you need the jre to get the jre out of that jar.
It seems not to be the best idea in general, to bundle your software with a special jre:
a) It will not be platformindependent, since you need different jars for each platform.
b) If the user already has a jre, he needs to download the jre twice, perhaps over a thin modem-line.
c) The user will not profit from enhancements in the jre.
d) You will not profit from this enhancements.
If you compile your classes without any deprecation-warnings, it will be able to run over some cycles of innovation, as the past shows.
If you have deprecated-Warnings today: Ok - perhaps you should look for someone who will port it to an actual state.
You may ship a jar-file with an appropriate manifest, claiming the Main-Class: ..., tell the user where to get the jre, and how to set up windows/ linux/ mac os/ ... to start jar's automatically by clicking the jar.
And you may add a bat-File for windows or a sh-Script for Linux, which calls java in the right way (And on Mac OS?).
Or you use jnlp - which seems to be a little difficult, and which I didn't try.
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, you can do it and here's how:
1. You'll need to create two files, a ".bat" and ".sh" for windows and linux/unix respectively. These are both simply command-line scripts. You then check to see if the command "java" works on both (what's the best way to do this? Anyone know?). If it does, the script simply invokes "java -jar YourJarFile". If it does not, then your script uses zip to pull the jre out of your jar file (do you have the license rights to even include the jre?), save it to disk. Then the batch file can execute that program to run the person through installation of the JRE.
NOTE: On windows, people need the WinZip command-line add-on to
use it from the command line. On Linux/unix it's built-in.
http://download.winzip.com/wzcline.exe //The add-on
2. Create the proper Manifest file so your jar file will be executable once the JRE is installed.
That's it!
 
Sam Smoot
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it is internal, I'm just going to have our support staff force the JRE install on all machines. Not the most elegant, but will at least put us all on the same page...
Thanks.
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are programs that will do this for you. They can create installs that include the JRE for you and can even bundle it all into a Windows Exe. For example, look at InstallAnywhere - they have a free version without all the bells and whistles, but it should do what you want. There are other companies/products that have something similar (and some are free).
brian
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!