aspose file tools*
The moose likes Java in General and the fly likes Packaging JRE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Packaging JRE" Watch "Packaging JRE" New topic
Author

Packaging JRE

Adam Teg
Ranch Hand

Joined: Jul 10, 2007
Posts: 58
I am building a standalone java application and want to package my own jre. What is the best way to do this? How to test my app to make sure it is using the packaged jre beause I also have one installed?

Thanks in advance
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38389
    
  23
Why provide your own runtime? That would lose your platform independence. The idea with Java is that the JRE is provided by the computer, and there is no need to change it.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
What features do you need that aren't provided in Sun's jre?
Can you tailor/extend what Sun provides to solve you problem?
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
If I've understood, you're saying you want to provide your application with the Sun JRE bundled into the installer (not your own version of the JRE) in order that you guarantee the correct version is installed on the target machine?

This is going to depend on what platform(s) you're working for. The neatest solution is provided by Linux/OS X packaging systems - so you could create a new package and, in Debian for example, specify the sun-java6-jre package as a dependency. That would make sure the Java 6 runtime is downloaded and installed before your program in a totally standard way and without involving any native code on your part. Perfect.

On Windows you'd need to look into a proprietary installer (or build your own in a native programming language like C++). For example: Advanced Installer.

Alternatively you could look into Java Web Start if your application is freely available, and just provide a download link on your website for the JRE. That will do an awful lot of native binding for you too (like putting icons on the desktop/programs menu) in a standard way.
[ June 22, 2008: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Adam Teg
Ranch Hand

Joined: Jul 10, 2007
Posts: 58
So I can't just jar the JRE and bundle it with my application and point to the JRE from my app? This has got to be possible. Is there some documentation on how to do this? The problem I am having is that when users install the my app, they don't have the right version of java. I don't want to ask them to install this but rather have my own.

-Adam
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
The point is: if they don't already have a JRE installed, how can you use a Java program to install the JRE? It won't run! That's why you need some native installer to install the JRE first (note the Sun JRE installer is native), then unpack your application for execution.

If you can guarantee your users have some early version of the JRE available, you could code a Java app for that early version and, say, have a ZIP file for extraction. However, then you've got the problem of needing to write specific code using an early Java language specification, for each operating system, and you'll likely miss things - like the registry hooks in Windows, all the symlinks and different standard install locations for Linux distros etc.

Once you get down to the level of saying "my users only use Windows" then you might as well have written a native Windows-only application! Though as I said before, lack of a standard package management system really makes Windows the difficult operating system for ensuring dependencies are met here.

You would also need to take care that you don't violate the Sun regulations on redistributing the runtime. You shouldn't, but just be careful.
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
And to answer the specific question:
So I can't just jar the JRE and bundle it with my application and point to the JRE from my app?
Certainly not if you mean putting the JRE and your classes in the same JAR - you would still need a JRE outside the JAR to unpack the archive and run the program in the first place! But by that point you've already loaded all the core Java runtime archives so you can't replace them in the classloader (plus all the native bindings would have been made and can't be replaced - you don't want to hit a point in your program where it suddenly finds an expected native interface is missing because you're using an old JRE version but newer runtime JARs).
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14113
    
  16

Here is a list of Open Source Installer Generators in Java. Some of them can automatically download and install a JRE if the user doesn't have it installed on his/her system.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Adam Teg
Ranch Hand

Joined: Jul 10, 2007
Posts: 58
Thanks Charles and Jesper.

I already have an installer and it is not in the list you guys suggested that handles JRE's. The major issue is that the jre installed does not have the JCE and a seperate JCE download is needed. Is there a way I can package the JCE by itself?
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
What version of the runtime are you using? JCE has been bundled in the JRE since 1.4 so you won't need a separate provider unless you want to use another library for additional features. In that case, since JCE uses the provider framework, it should be sufficient just to include the JAR(s) on the classpath (the JCE SPI will look for providers registered by the JARs automatically). You can do this in a JAR using the manifest - for example:

Manifest-Version: 1.0
Class-Path: MyUtils.jar ASecond.jar [etc...]

Then just include the JARs you need in the same directory as your main executable JAR. Your installer should cope fine with this? Does that help?
 
wood burning stoves
 
subject: Packaging JRE