I want to be able to deploy my Java application so that it will run on any target (even if the target doesn't have Java installed)
I'm told I must distribute the JRE with my application. Do I literally take a copy of the JRE folder for Windows and one for Linux and have a shell to execute both?
Or are there further steps?
I think the best way to do this is to use an installer.
BitRock, Install4j, etc...
The installer will take care to install the JRE if it doesn't exist on the machine.
Moreover the installers above are multi-platform.
Related
I have a question about deploying windows application with java module.
I have windows application with several modules. One of these modules is written in java and is packaged as jar-archive. And if there's need for using this module, the application ask jre to start execute this jar.
For this time during application installation it's initialized jre installation.
I would like to understand the following.
Is it possible to install during application installation silently install jre in the application directory. So it jre copy could be used by the application.
I'm talking about structure like this:
/app
/app/jre
/app/modules/myModule.jar
So if it's needed to run myModule.jar I could do it with java from app/jre/bin ?
I saw something like that at Spark messenger (http://www.igniterealtime.org/projects/spark/). This application uses its own jre, which is installed at /Spark/jre/. But as I understand, this application is written in java and builded as a windows distributive using install4j.
I tried to find the answer to my question, but maybe I'm doing something wrong, I always find a solution of creating an exe-wrapper for jar file.
I would like to know about possibility to deploy application with installing jre locally in application folder.
You could ideally have used Java Web Start in the past.
Currently, you can use javapackager.
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javapackager.html
The javapackager command allows developers to create standalone native install bundles that do not require a separate JRE installation. The native options include: installer, image, exe, msi, dmg, rpm, and deb.
This is ideal for desktop applications, where the user may not have their own JRE installed and just wants the program to run. It may not be appropriate for server-based applications where an administrator would want full control over the environment.
https://blogs.oracle.com/java-platform-group/entry/java_web_start_in_or
In your /app/jre/bin folder there should be an executable binary called java. So in your folder /app/modules you can run
/app/jre/bin/java -jar myModule.jar
That should work.
Let's say I want to distribute a Java desktop app in a native-like way. Is there a tool/technique to build Java desktop application installers that will automatically and seamlessly install a JVM if one does not exist on a system already?
Installing Java apps for users who do not have a JVM is a 2-step process (first install the JVM, then the app). I'd like to match the experience of installing a typical native desktop app by making it a one-step process (or as much one-step-ish as possible).
For Windows, I suggest using NSIS installer to wrap installation of the JRE and your program. That will allow real "installation", ie. JRE will be installed to Program Files and it will be possible to uninstall it from Windows control panel ("public JRE"). You need to bundle the JRE installer for that.
Alternatively, you can bundle the whole JRE ("private JRE") together with your program. You can use Launch4J which configures the launch of your Java application (VM options, classpath etc.) as an EXE file, have the JRE somewhere as one of the folders of your distribution and point Launch4J to use it.
Or, simply have the unpacked JRE ("private JRE") in one of the folders of your distribution and use relative paths to use that one instead of the one installed on the system.
The advantage of a private JRE is that you control which Java version it is. With a public JRE, the user may be able to uninstall it or change the version and then come complaining that your program is not working ;)
For Linux, if you distribute you application as an RPM, you can just declare a Java package to be your dependency. Linux package manager should take care of it all. On the other hand, you can still bundle JRE in your own RPM to be independent of the "main" version installed on the user's machine.
I've made a little GUI program to enter contents then send "javamail" to my email. I have to import many jar libraries from javamail-1.4.5 and then I build it (shift + f11) to jar, then use exe4j to make it exe (also add all the jars from the libraries in the /dist/lib) and version of jre from 1.5 to 1.7 (I'm using 1.7 to make this app). It works smoothly on my computer but when I give the exe to others computer. It said:
"No JVM could be found on your system. Please define EXE4J_JAVA_HOME to point to an installed 32-bit JDK or JRE or download a JRE from www.java.com"
I think they must install the JDK in order to be able to run the app. But it may be confusing to many of my friends who don't know about computing. Is there anyway can they use that send-javamail-app without asking them to install the JDK?
Thanks in advance and sorry for my English!
It's quite simple.
After you have done basic steps as set the name, icon, etc, in step number 6 JRE is where the magic happens:
Click Advanced Options and select Search sequence
Click to add new item + and select directory
Select your jre directory, it must be a relative path
Put your new item at the first position in list
After that what you have to do is release your exe with the jre directory together, to do that usually I use Inno Setup Compiler to create a installer.
You can bundle the JRE with your product, this is the best way you can achieve without bothering your buddies. The size of your application will increase.
JRE is required to run any java application.
Hope this helps.
Java Runtime Environment (JRE) is required to run the Java application. In order to install JRE on a computer without Java installed, you must either bundle it (put it inside your application), or ask your friends to download JRE.
I don't know exactly how to bundle JRE, but the question Bundling the JRE with a Java application can probably help.
Maybe my personal project Java Customization Builder can help you, it analyzes the classes used by your program, and slim these classes from jars, and it also analyzes jvm files used by your program. Then it make an executable file and pack200 the jre runtime and your program.
JCB Project Introduction:
Java Customization Builder is a tool which customizes your java application and JRE.
It is a java application building tool enabling you to generate a very small java archive package which has a slimmed jre. For the swing application, the archive is less than 5M, for the SWT application, the archive is less than 3M usually. And the customed java applicaton can run on the Windows which doesn't install a JRE, and be loaded by an executable.
JCB project page: http://jcb.sourceforge.net
What's the best way to package Java software for running on Windows? Is there a standard for writing .BAT files which can discover the latest installed JRE on the machine? Are there any Maven plugins for this? What's the deal with executable Jar files?
I would without any doubt recommand you to use Java Web Start, as it allows you easy control over version used (and by far the easier to use update mechanism available nowadays).
Depends on what you need.
We've found that using the One-JAR + JSmooth gives a very good user experience as it allows us to distribute a single EXE-file which can be put anywhere on the users system, as opposed to having installation binaries, which need to be installed and uninstalled etc. etc. etc. JSMooth checks for the existance of the appropriate Java runtime, and redirects to the official download site if none is found.
The reason for One-jar is that you generally need to use library jars which is best to have separately but JSmooth only allows for a single jar file.
Also the One-Jar SDK and JSmooth is scriptable without being tied to Windows, so we can build new versions on our Hudson engine running on Linux.
In the past I've used a java installer package like launchForJ. However, a lot of these packages use Java so you may need to a batch or simple executable written in native windows code that does a quick check to see if Java is already installed then run the installer.
Since Java uses system variables during install you should be able to check if the version (or higher) that you require exists in this way.
The standard way would be to use Java Web Start.
Using Java Web Start technology, standalone Java software applications can be deployed with a single click over the network. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java Runtime Environment (JRE)
Maven has a Webstart Maven Plugin to help building application bundles that can be deployed via Web Start.
An alternative solution would be to use a cross-platform installer generator to generate, well, an installer. I personally like IzPack (I think that JSmooth is very similar but I have more experience with IzPack) and, if you are specifically targeting the Windows platform, you could use IzPack to Build [a] Native Windows Installers with IzPack Native Launcher:
A problem still arise with IzPack when
the target system does not have a JRE
installed. The user needs to first
install it and then run the IzPack
installer. This is not a problem with
Linux or BSD users since they are
generally skilled and they know how to
do that by hand or with a packaging
system (RPM, DEB, ebuilds, ports,
...). Similarly, a Mac OS X user will
not have much problems since it is
available with the operating system.
However the situation is more
complicated on the Windows platform as
a JRE must be installed. Worse,
several instances can be installed in
a sometimes messy situation.
The IzPack Native Launcher tries to
solve this problem. It is a C++ native
application that is available under
the very permissive MIT License and
that uses wxWidgets for the GUI. It is
thus cross-platform (for the
historians: it was first developed on
a FreeBSD box), but most people will
need it on Windows. It uses a simple
configuration file and will first
check for a JRE. If none can be found,
it will pop-up a dialog to let the
user choose between the following
options:
manually specify a JRE location
download one from the Internet
install one that is provided by the packager (if available).
IzPack also offers a Maven Plugin. Worth the check.
These fine folks are my users: http://www.youtube.com/watch?v=o4MwTvtyrUQ
If you don't want to enjoy the video here is the gist: my users can't tell between a file and a folder, between a browser and a web site.
I need to create a Java web app (Tomcat or Jetty) and deploy it in as many of their computers, Windows and Mac.
The question is: Is there a mechanism to distribute an app with its own JRE? (in the Tcl world there are starpacks and starkits, in the Python world there's py2exe and others, that's the idea). And also, is it legal? I know the VM is open source but I'm not clear about the libraries, and I know about GNU Classpath but I don't know if all the packages are there.
I don't want to depend on the installed JRE or on the user having enough privileges to install one. On the Mac I don't want to depend on Apple (I had to switch from Tiger to Snow Leopard just to have Java 1.6, I can't put my users in that position)
Any info greatly appreciated.
Thanks!
jb
edit: I'm wondering if I can just paste the JRE folder under my app folder. Is that allowed?
We use Install4j at our workplace. It takes care of installation and installs the JRE if needed too. Its not free though. And at least the version we use doesn't provide Mac users with a bundled JRE. But as far as I was able to find out, that was due to some restrictions by Apple. Macs come with their own JRE and if your user has a Mac, its safe to assume they have a JRE installed. Although, if the JRE is an older version than the one you like, then they would have to use Software Update to check if a newer version is available and install it.
To run your application, a user needs the J2SE Runtime Environment,
which is freely available from Sun. Or, You can redistribute the
J2SE Runtime Environment for free with your application, according
to the terms of the Runtime Environment's license.
From http://java.sun.com/j2se/1.5.0/jre/README
I haven't read the fine print, it seems that Sun intends for people to redistribute the JRE. Also, there are many products (e.g. install4j) that make it easy for you to redistribute the JRE, so it seems to be legal.
As to the rest of it, you could then also bundle tomcat, with the built in Service so your app is automatically started, and create a shortcut on the desktop to your local webapp, so users are freed from typing ht tp://localhost:8080/webapp. There are plenty of FOSS installers (e.g. izpack) that will allow your users to install the package, and manage creation of desktop shortcuts. You mentioned preferring not using an installer, but even unzipping is kind of installing - your users have to choose a directory that they have write access to, and this is no different with a fully fledged installer.
But, given the capabilities of your users, is a locally installed solution the most suited to them? An online solution might offer simpler deployment (e.g. Java web start, or even as an applet.)
In OS X you pretty much are stuck with whatever Apple provides you. In other platforms, it is not needed to run a JRE installer (which you correctly point out your users may not be able to do), just bundle a JRE folder alongside your app. That is what many of our users do (my company has a multiplatform installer called InstallBuilder) and we have packaged many Java web apps that way. You can take a look at some of them at BitNami (they are all free)
Or in short, you can try this:
Make a self executable jar file of your app.
Provide your users small JRE setup (appx 15MB for jre6u7) along with your app.
Now create a batch file(for windows) which will first execute the JRE installer.
Then select path to installed JRE's 'bin' folder.
Now after this write 'java -jar yourAppName.jar' in the script to run your executable jar file.
eg: for win.bat write the following:
jre-6u7-windows-i586-p :: this will start the JRE installer
C:\Program Files\Java\jre1.6.0_07\bin\java -jar yourAppName.jar :: this will start your app
You can create such scripts for Mac and Linux also.