This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Packaging JRE

 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adam Teg
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic