Installing Java executables on Windows 10 machines by example - java

I imagine some Java gurus with experience delivering Java apps on Windows desktops will be able to ace this one. I've always been a Mac/Linux Java developer so this is uncharted territory for me :-/.
I have to write a Java 8 Swing application and install it on a Windows 10 (64-bit) machine. My gameplan is to package the app as an executable JAR and wrap it with Launch4J, so that it looks like a native Windows EXE (.exe file). However its a little bit more complication than that when it comes to the distribution:
There will be the JAR/EXE as mentioned above, lets call it myapp.exe (built from myapp.jar)
The app will output logs to a (local?) directory, myapp.log
The app will load a config file at runtime, myapp.properties
The distribution should also contain the User's Guide, MyApp User Guide.html
Let's assume a Java 8 JRE/JDK is already installed on the machine, so we don't need to worry about installing Java itself.
The installation process must be simple and include:
Removing the old version (and all of its other artifacts such as the log file, config/properties file, user guide, etc) off the machine completely
Installing the new version at either the Windows 10 default location, or allowing the user to specify a different location
Additionally, if at all possible, I'd like the installation process to include:
A requirements check for things like minimum memory and disk space, OS version info/compatibility (i.e. make sure its being installed on Windows 10, etc.)
Provide an easy-to-use wizard such as an MSI that the user can click though
Optionally install shortcuts to the user's Desktop
Given all this, I'm wondering what my options are in the modern Windows 10/Java/Launch4J landscape. Are there tools that will help me script together MSIs quickly, or do I have to write my own in, say, C#/.NET and have that be a separate binary/project? If MSIs aren't an option, what options exist that might hit all my bullets above?
I realize I could just distribute the whole thing as a ZIP, and have the installation process look something like:
Save the ZIP to some place on the user's machine, say, the Desktop
Move the previous app and its artifacts to the trash, manually
Unzip the new ZIP
However that feels janky and I'm looking for something more professional. Any solutions here?

JDK 8 is bundled with a tool called javapackager (formerly javafxpackager) which is part of JavaFX. However, you can use it package java swing application without using JavaFX. This tool can generate an installer file (exe or msi) which contains the application and the Java runtime as well.
Here is an example:
javapackager -deploy -native exe -Bruntime="C:\Program Files\Java\jdk1.8.0_66\jre" -Bicon=app_icon.ico -BsystemWide=true -BshortcutHint=true -outdir packages -outfile appFile -srcdir dist -srcfiles MyApp.jar;COPYING.txt -appclass somePackage.MainClass -BlicenseFile=COPYING.txt -name appName -title "The application name"
For more information, see adding icon to bundle using javapackager
There is also a new tool called jpackage which is based on javapackager. It is proposed to be released with the next JDK release, JDK 14. Note that javapackager was removed from JDK since version 11 as part of the removal of JavaFX.
See A Brief Example Using the Early Access jpackage Utility

Tools: Some deployment tools information:
Multi-Platform Installers
List of the major MSI installer tools
WiX quick start tips (the open source, free tool with a heavy learning curve)
"Hello WiX - step-by-step in Visual Studio"
"Hello World" - WiX style
Advanced Installer: As stated in a comment above you can use Advanced Installer to install Java applications on Windows and Mac (no Linux support).
Videos: Here are some videos from Advanced Installer (commercial tool) on Java installations:
Hello Java Installer: 1 minute video that shows the basics of installing a Java application
List of Java-related videos: https://www.youtube.com/user/AdvancedInstaller/search?query=java+jre
Tutorial (to read): Package your Java application for Windows and for Mac OS. Java landing page.
Digression: Not Java as such - do have a skim. Auto-updating applications using various deployment technologies: What is the best practice to auto upgrade MSI based application?
Links:
Make Installer of java Application
Installer for Java Web Application
How to create windows installer
How to create a MSI Windows installer for a Java program?
Old: How can I convert my Java program to an .exe file?

Related

JavaFX and IntelliJ 14 Alternative Self Packaging to EXE

I am using Ubuntu 14.04 and I am trying to self package a JavaFX app in IntelliJ 14. This has been wasting my time for past 2 days. It took me less to develop the app. Any help will be greatly appreciated.
What I want is a self-contained package that will run on any platform (mainly Windows). Now I am using Ubuntu and I want this:
1 - Using my current OS (Ubuntu 14.04) I want to create an exe file that will act as an installer or simple executable for windows whatever it is
produced.
I tried this, http://launch4j.sourceforge.net/docs.html and Excelsior JET, the first one does not create a self-contained app, and the second one did not run.
2 - I tried this http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm
I tried using the javafxpackager which in Java8 it has been renamed into javapackager, and I ran this:
javapackager -deploy -native exe -srcfiles src/ -outdir out/artifacts -outfile GreekTest -appclass foo.Main
What it did was to just generate a bunch of java files in the ourdir. No exe.
From the link I posted above,
First of all I have no such XML file as in my JavaFX app directory that has a task <fx:deploy> is this generated by the user?
3 - IntelliJ Build Artifacts Tools just generate a jar file, no-self contained app.
4 - I also want to avoid Maven/Ant as I don't know how to use it.
Any help?
Check out Capsule.
Re Excelsior JET not working, you must be on a 64-bit Ubuntu system, and it needs some 32-bit libraries. Here is an excerpt from the installation instructions:
Important notice for 64-bit Linux users:
As of version 10.5, some key components of the 64‑bit version of
Excelsior JET for Linux remain 32‑bit. Most 64‑bit Linux systems do
not have the 32‑bit libraries installed by default. If you receive a
"No such file or directory" or "cannot execute binary file" message on
an attempt to run any Excelsior JET component, or one of its graphical
tools fails on startup with
Exception in thread "main" java.lang.NoClassDefFoundError: java.awt.Frame
you need to install those libraries.
On Ubuntu/Debian, the procedure used to be as simple as:
sudo apt-get install ia32-libs
but in the latest versions you have to list the libraries explicitly:
sudo apt-get install libc6:i386 libx11-6:i386 libxext6:i386 libxrender1:i386 libxi6:i386 libxtst6:i386
The list of libraries and installation procedure in other distros may
differ.
(Full 64‑bit port is our top priority, but doing it right takes time.
Please bear with us.)
In any case, it won't help you create "a self-contained package that will run on any platform (mainly Windows)." First, it creates a native executable that will run on either Windows, OS X, or Linux, but not on two or three of these. Second, it does not support cross-compilation as of version 10.5, so you need Excelsior JET for Windows to create a Windows EXE.

Installing Java on a Flash Drive

I'm really tired of computers not having the necessary Java version I need, or I don't have admin privileges to install it. I've seen tons of windows tutorials, but I'm on a Mac. So can someone tell me how to put Java 7/8 on a flash drive, and how to create a script to run a jar file with the version on my drive I have selected? Thanks! I'm on Mac OS X 10.10
Based on your comment to another answer
I have a computer I can do it on with admin privileges
It sounds like you just want to have the JVM/JDK on some portable media that you can run from after you plug it into another computer. This should be simple assuming you only plan on using it on comparable systems. For example, you won't reliably (or at all) be able to install Mac x64 java binaries on a flash drive and try to run it on a Windows machine.
So assuming you only intend to run it on comparable machines, it's as simple as copying the directory structure from the root of the Java install directory. On my Mac OsX 10.9.5 it's /Library/Java/Home. Once you have it on the drive, you just plug it into another Mac. It should automount and you open up a terminal to the root of that mount. cd into the $JAVACOPY/bin (where $JAVACOPY is the directory structure you copied) and you can run ./java -version to verify you are running it.
If all is well after doing that, you can launch any JAR file from that flash drive mount directory with
cd /Volumes/flashMount/Java/Home/;
./bin/java -jar /Users/myuserid/myJar.jar
Keep in mind that Java doesn't strictly require any of the formal install process that systems like Mac and Windows surround it with. All of the fluff involved with "installing" java is about setting up the system to use whichever Java version is installed without the user having to know or care. But you can have as many versions of java as you want in the file system without "installing" them and they should all function just fine (ignoring classpath collisions for certain libraries.)

Create Windows installer on non-Windows system

I want to create an Windows installer for a Java application, though the native executables already exist and hence it simplifies to installing any kind of files. This question is similar to this one, but with following restrictions:
the Windows installer must be a native one, it must require an installed or bundled JRE
the installer creation must be platform independent, so it can be run on Windows, Linux or OS X (e.g. Java/ANT-based installer creation)
Currently, depending on our specific product, we are using WiX and InnoSetup, but both require the build process to be running on Windows. I want to avoid using Windows or Wine, but search a tool which already does it on all platforms.
Have you tried Wine compatability for Wix & InnoSetup? Also you can make scripts that start virtual machines to do stuff like this automatically. I have a Linux system that makes Windows XP/Windows 7 installation files using a combination of Wine and VirtualBox scripting.

launching java applications in a cross platform way

I have a Java program, let's say it's called MyApp.jar
To run it on Linux, I just write a shell script called myapp.sh, which simply runs java -jar MyApp.jar and double click on it. Everything works well.
On Windows 7, I cannot assume that the java command will be in everyone's path (if that's what you call it on Windows), so I have to have a workaround and do something like create a batch script with this in it: "C:\Program Files (x86)\Java\jre6\bin\java.exe" -jar MyApp.jar, which is obviously a Bad Solution... and it doesn't work on XP or Vista. It works on most Windows 7 machines though.
My application ships as a .zip file, the user extracts it to a folder MyApp, and then ideally will double click on something to invoke the program. So far it has a .sh script for Linux users to double click on, and a batch script for Windows 7 users (it works in most cases). It creates and consumes files in its own directory (MyApp).
What is the best way to invoke this program in a cross platform way?
Thanks!
As mentioned by biziclop, Java Web Start is commonly used to install/launch/update Java desktop apps.
As far as the JRE goes, it is usually sufficient to use the deployJava.js linked from that page above to ensure minimum necessary JRE is installed, and the elements in the JNLP file to specify any JRE micro-versions that are supported for the app.
Application launch
JWS can install desktop shortcuts and menu items when supported by the OS. Those can be specified in the launch file, or added/removed at run-time using services of the JNLP API.
If you can't deliver Java with your application, it might be a good solution to use JAVA_HOME to start it. It is set on, well... not all but many systems.
Definitly you should not use C:\Program Files (x86)... it is much better to use the environment variable %ProgramFiles%
Java application require a java runtime environment with a certain version to be installed on the target system.
The most convenient way, to my opinion, is to ship all libraries and documentation in a single archive and add start scripts for windows and *nix systems.
You could ship a JRE with your application too but then you'd have to support builds for different platforms...

Multiple Java versions running concurrently under Windows

We have a couple of applications running on Java 5 and would like now to bring in an application based on Java 6. Can both java versions live together under Windows?
Is there any control panel to set the appropriate Java version for different applications, or any other way to set up, what version of Java will be used to run that particular application?
Of course you can use multiple versions of Java under Windows. And different applications can use different Java versions. How is your application started? Usually you will have a batch file where there is something like
java ...
This will search the Java executable using the PATH variable. So if Java 5 is first on the PATH, you will have problems running a Java 6 application. You should then modify the batch file to use a certain Java version e.g. by defining a environment variable JAVA6HOME with the value C:\java\java6 (if Java 6 is installed in this directory) and change the batch file calling
%JAVA6HOME%\bin\java ...
I was appalled at the clumsiness of the CLASSPATH, JAVA_HOME, and PATH ideas, in Windows, to keep track of Java files. I got here, because of multiple JREs, and how to content with it. Without regurgitating information, from a guy much more clever than me, I would rather point to to his article on this issue, which for me, resolves it perfectly.
Article by: Ted Neward: Multiple Java Homes: Giving Java Apps Their Own JRE
With the exponential growth of Java as a server-side development language has come an equivablent
exponential growth in Java development tools, environments, frameworks, and extensions.
Unfortunately, not all of these tools play nicely together under the same Java VM installation. Some
require a Servlet 2.1-compliant environment, some require 2.2. Some only run under JDK 1.2 or above,
some under JDK 1.1 (and no higher). Some require the "com.sun.swing" packages from pre-Swing 1.0
days, others require the "javax.swing" package names.
Worse yet, this problem can be found even within the corporate enterprise, as systems developed using
Java from just six months ago may suddenly "not work" due to the installation of some Java Extension
required by a new (seemingly unrelated) application release. This can complicate deployment of Java
applications across the corporation, and lead customers to wonder precisely why, five years after the
start of the infamous "Installing-this-app-breaks-my-system" woes began with Microsoft's DLL schemes,
we still haven't progressed much beyond that. (In fact, the new .NET initiative actually seeks to solve the
infamous "DLL-Hell" problem just described.)
This paper describes how to configure a Java installation such that a given application receives its own,
private, JRE, allowing multiple Java environments to coexist without driving customers (or system
administrators) insane...
It is absolutely possible to install side-by-side several JRE/JDK versions. Moreover, you don't have to do anything special for that to happen, as Sun is creating a different folder for each (under Program Files).
There is no control panel to check which JRE works for each application. Basically, the JRE that will work would be the first in your PATH environment variable. You can change that, or the JAVA_HOME variable, or create specific cmd/bat files to launch the applications you desire, each with a different JRE in path.
We can install multiple versions of Java Development kits on the same machine using SDKMan.
Some points about SDKMan are as following:
SDKMan is free to use and it is developed by the open source community.
SDKMan is written in bash and it only requires curl and zip/unzip programs to be present on your system.
SDKMan can install around 29 Software Development Kits for the JVM such as Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x.
We do not need to worry about setting the _HOME and PATH environment variables because SDKMan handles it automatically.
SDKMan can run on any UNIX based platforms such as Mac OSX, Linux, Cygwin, Solaris and FreeBSD and we can install it using following commands:
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
Because SDKMan is written in bash and only requires curl and zip/unzip to be present on your system. You can install SDKMan on windows as well either by first installing Cygwin or Git Bash for Windows environment and then running above commands.
Command sdk list java will give us a list of java versions which we can install using SDKMan.
Installing Java 8
$ sdk install java 8.0.201-oracle
Installing Java 9
$ sdk install java 9.0.4-open
Installing Java 11
$ sdk install java 11.0.2-open
Uninstalling a Java version
In case you want to uninstall any JDK version e.g., 11.0.2-open you can do that as follows:
$ sdk uninstall java 11.0.2-open
Switching current Java version
If you want to activate one version of JDK for all terminals and applications, you can use the command
sdk default java <your-java_version>
Above commands will also update the PATH and JAVA_HOME variables automatically. You can read more on my article How to Install Multiple Versions of Java on the Same Machine.
It should be possible changing setting the JAVA_HOME environment variable differently for specific applications.
When starting from the command line or from a batch script you can use set JAVA_HOME=C:\...\j2dskXXX to change the JAVA_HOME environment.
It is possible that you also need to change the PATH environment variable to use the correct java binary. To do this you can use set PATH=%JAVA_HOME%\bin;%PATH%.
I use a simple script when starting JMeter with my own java version
setlocal
set JAVA_HOME="c:\java8"
set PATH=%JAVA_HOME%\bin;%PATH%;
java -version
To have a java "portable"
you can use this method here:
https://www.whitebyte.info/programming/java/how-to-install-a-portable-jdk-in-windows-without-admin-rights
Or use links. While it is rather unpleasant to update the PATH in a running environment, it's easy to recreate a link to a new version of JRE/JDK. So:
install different versions of JDK you want to use
create a link to that folder either by junction or by built-in mklink command
set the PATH to the link
If other version of java is to be used, delete the link, create a new one, PATH/JAVA_HOME/hardcoded scripts remain untouched
Invoking Java with "java -version:1.5", etc. should run with the correct version of Java. (Obviously replace 1.5 with the version you want.)
If Java is properly installed on Windows there are paths to the vm for each version stored in the registry which it uses so you don't need to mess about with environment versions on Windows.
If you use Java Web Start (you can start applications from any URL, even the local file system) it will take care of finding the right version for your application.
Using Java Web Start, you can install multiple JRE, then call what you need.
On win, you can make a .bat file:
1- online version:
<your_JRE_version\bin\javaws.exe> -localfile -J-Djnlp.application.href=<the url of .jnlp file.jnlp> -localfile -J "<path_temp_jnlp_file_.jnlp>"
2- launch from cache:
<your_JRE_version\bin\javaws.exe> -localfile -J "<path_of_your_local_jnlp_file.jnlp>"

Categories

Resources