How to implement auto update in Java? - java

All:
I am facing a problem here, my app is composed by some jar files and some other files, they are all located in one directory. I am planning to implement an auto-update feature. When the app know there is a new version on the server, it will download a zip file to temp directory. After downloading, it will ask customer if he'd like to install it. If yes, my app will exit and I need to unzip the zip file and overwrite all files in the original directory. Now I am wondering:
How can I unzip the file and overwrite the directory? Create a script (which means I need to write bat for Windows and shell for other platforms)? Create a java class to do it?
How can I start this script/ java class after exiting?
Once the job is done, how do I delete the installer? Keep it in temp directory and check it out when new version app start?
From later comments:
I know JWS is a good choice, but for reason "my boss denied", I can't use it.

There could be several approaches. Since you say the application is cross-platform, it would be wise to use Java for update.
You can create a small jar file which will handle the update process. It could be part of the initial application (with the assumption it won't be updated) or it could be part of the update package (then you can update it as well).
So your application downloads zip, unpacks it to a temporary directory and starts the updater, then it exits. The updater copies new jars over the old ones.
Yet it's better to not reinvent the wheel. Consider using JWS: it provides more features and requires less effort to implement. There must be good reasons to deny JWS. You should persuade your boss by explaining the benefits of using JWS.

Since the app. has a GUI (judging by the Swing tag), deploy it using Java Web Start:
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

Related

Difference between running java program using jar file or installing onto a system using Izpack?

is there a difference between using my java program as a jar file as opposed to using a software like IzPack to create an installer and install it onto a system ? Does it make any difference performance wise and what are some benefits ( if any) of going either way ( aside from creating shortcuts) ?
Using jar directly allows it to be used in other machines.
If you were to use IzPack to create an installer, it will still work in other systems after installation.
As far as I know, there is none performance-wise.
Your question is very vague.
Some tools like WinRun4J can be helpful to optimize the amount of memory available for your program at startup. WinRun4J and PackR allow to use a custom name for the executable which is useful if you want to hide the fact that your program uses Java.
Some web browsers under some operating systems break the downloaded JARs by wrapping them in ZIPs for "security purposes".
Some tools use a fat JAR in input and produce a kind a native bundle which is more familiar for the end users, PackR and JNDT produce APP files for OS X, JNDT produce RPM and DEB packages for GNU Linux.
Whether it is a jar file or Izpack installed java app, there won't be any performance difference.
The main differentiator I see is the user experience. For simple applications it doesn't make much difference. But for any medium to large scale application which needs to perform some prerequisite checks, capture configuration data from user, upgrade the application etc, installer helps a lot in making installation more user-friendly.
So using Izpack or in any installer in general, improves the user experience. Some of them I can think of are:
Installer can perform any software prerequisite checks before
installing the application.
Allows user to choose the installation location
Prompts for any required input parameters or configuration and validating it
Allows the user to enter these input or configuration data
Upgrades the software by taking care of any data software or data/configuration migrating and ensures proper rollback in case of
failures.
Without the installer most of these need manual intervention and installation becomes more error prone, manual errors and becomes a tedious job for the user.

How to distribute Application which has multiple class Libraries [duplicate]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Java is one of my programming languages of choice. I always run into the problem though of distributing my application to end-users.
Giving a user a JAR is not always as user friendly as I would like and using Java WebStart requires that I maintain a web server.
What's the best way to distribute a Java application? What if the Java application needs to install artifacts to the user's computer? Are there any good Java installation/packaging systems out there?
There are a variety of solutions, depending on your distribution requirements.
Just use a jar. This assumes that the user has the the correct java version installed, otherwise the user will get "class-file format version" exceptions. This is fine for internal distribution inside a company.
Use launch4j and an installer like NSIS. This gives you a lot more control, although the user can still do stupid stuff like un-installing the java runtime. This is probably the most popular approach, and what I currently use.
Use Webstart. This also assumes that the user has the correct java version installed, but it's a lot easier to get going. My experience is that this is fine for tightly controlled intranet environments, but becomes a pain with larger deployments because it has some many weird failures. It may get better with the new plug-in technology in Java 1.7.
Use a native-code compiler like Excelsior JET and distribute as a executable, or wrap it up in an installer. Expensive, and it generally ties you to a slightly older version of java, and there is some pain with dynamic class-loading, but its very effective for large-scale deployment where you need to minimise your support hassles.
advanced installer makes it easy to package java apps as windows executables, and it's quite flexible in the way you can set it up. I've found that for distributing java applications to windows clients, this is the easiest way to go.
JSmooth is a simple program that takes your jar and wraps it up in a standard windows executable file. It comes with a simple GUI that allows you to configure the required JVM, bundle it with the application or provide an option to download it if it's not already installed. You can send the exe file as is or zip it with possible dependencies (or let the program download the extra dependencies from the net on startup). It's also free, as in beer and speech, which may (or may not) be a good thing.
If it's a real GUI-having end user application you should ignore the lanaguage in which you wrote the program (Java) and use a native installer for each of your chosen platforms. Mac folks want a .dmg and on windows a .msi or a .exe installer is the way to go. On Windows I prefer NSIS from NullSoft only because it's less objectionable than InstallShield or InstallAnywhere. On OSX you can count on the JVM already being there. On Windows you'll need to check and install it for them if necessary. Linux people won't run Java GUI applications, and the few that will, know what to do with an executable .jar.
It depends on how sophisticated your target users are. In most cases you want to isolate them from the fact that you are running a Java-based app. Give them with a native installer that does the right thing (create start menu entries, launchers, register with add/remove programs, etc.) and already bundles a Java runtime (so the user does not need to know or care about it). I would like to suggest our cross platform installation tool, BitRock InstallBuilder. Although it is not Java-based, it is commonly used to package Java applications. It can be easily integrated with Ant and you can build Windows installers from Unix/Linux/Mac and the other way around. Because the generated installers are native, they do not require a self-extraction step or a JRE to be already present in the target system, which means smaller installers and saves you some headaches. I also would like to mention we have free licenses for open source projects
Although I haven't used NSIS (Nullsoft Scriptable Installer System) myself, there are install scripts that will check whether or not the required JRE is installed on the target system.
Many sample scripts are available from the Code Examples and Real World Installers pages, such as:
Java Launcher with automatic JRE installation
Simple Java Runtime Download Script
(Please note that I haven't actually used any of the scripts, so please don't take it as an endorsement.)
executable files are best but they are platform limited i.e. use gcj : http://gcc.gnu.org/java/ for linux to produce executables and use launch4j : http://launch4j.sourceforge.net/ to produce windows executables.
To package on linux you can use any rpm or deb packager. For win32 try http://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System
I needed a way to package my project and its dependencies into a single jar file.
I found what I needed using the Maven2 Assembly plugin: Maven2 Assembly plugin
This appears to duplicate the functionality of one-jar, but requires no additional configuration to get it going.
For simple Java apps I like to use Jar's. It is very simple to distribute one file that a user can just click on (Windows), or
java -jar jarname.jar
IMHO, jar is the way to go when simplicity is a main requirement.
I develop eclipse RCP applications. Normally to start an eclipse application an executable launcher is included. I include the java virtual machine inside the application folder in a /jre sub directory to ensure that the right java version will be used.
Then we package with Inno Setup for installation on the user's machine.
What's the best way to distribute a
Java application? What if the Java
application needs to install artifacts
to the user's computer? Are there any
good Java installation/packaging
systems out there?
In my experience (from evaluating a number of options), install4j is a good solution. It creates native installers for any platform, and is specifically geared towards installing Java apps. For details, see "Features" on its website.
install4j is a commercial tool, though. Especially if your needs are relatively simple (just distribute an application and install some artifacts), many other good options exist, including free ones (like izPack or the already mentioned Lauch4j). But you asked for the best way, and to my current knowledge install4j is the one, especially for distributing larger or more complicated Java (EE) apps.
The best answer depends on the platform. For deployment on Windows, I have had good results using a combination of one-jar and launch4j. It did take a little while to set up my build environment properly (ant scripts, mostly) but now it's fairly painless.
Well from my point of view the superior distribution mechanism is to use something like ClickOnce, or WebStart technology. You just deploy the version to the server and it gets automatically to the clients when the version is released.
Also the Eclipse RCP platform contains UpdateManager that does what WebStart do, but also much more.
Since I am using Maven2 for building, the deployment is just a piece of cake: copy the built jar to the location on the server, update the jnlp file if needed and you are done.
installanywhere is good but expensive one - i have not found (as) good free one
I would zip the jar file along with other dependent jars, configuration files and documentation along with a run.bat/run.sh. End user should be able unzip it to any location and edit the run.bat if required (It should run without editing in most of the cases).
An installer may be useful if you want to create entries in start menu, desktop, system tray etc.
As a user I prefer unzip and run kind of installation (no start menu entries please). However People outside IT industry may have different preferences. So if the application is largely targeted for developers zip-run.bat route and applications for general public may be installed using a installer.

How to make Windows autoview a file with my program, and how to make the program read it?

I want it like when we do "open with" and then choose Notepad. So that when I "open with" a file there will be my program in the list. How to associate a file type with my program?
How to make the program handle the file?
Deploy the app. using Java Web Start.
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
This demo. of the file service is deployed using JWS (on OS X, *nix and Windows) and declares an interest in the .zzz file-type.
Best thing would be to create an EXE wrapper for your Java program:
How can I convert my Java program to an .exe file?
and
Best free tool to build an exe from Java code?
are relevant. Then you would need to create a file association. See this KB article on how to do it manually:
http://support.microsoft.com/kb/307859
If you use an installer package to package your app you would have to research on how to accomplish this automatically when your program installs.

Installer for Java Applications

I need to create an installer for my java desktop application. I don't like to code an installer by hand. is there anyway I can create an installer for Java applications?
If your looking to create an installer for windows applications check out Advanced Installer. For linux based machines, I'd just got with the regular tar.gz file and a README file.
Pack Jacket software:
This is a freeware with a simple GUI. Available to download from sourceforge. This file is capable of creating installers with extensions .exe, .jar and much more. The complete tutorial is available in youtube. Just search "How to make installer for regular java project" in youtube and the first result, you will find the tutorial (I tried to paste the link here, but stackoverflow didn't allow it :( ).
IZPack:
IZpack doesn't have any GUI, just some files. You have to do it manually. It takes xml files as parameters which instruct it how to create the installer. The tutorial for using IZpack is here. I am using IZpack and personally I like it more than pack jacket.
There are more apps for creating these installers, but according to my knowledge these are the most famous because I have seen these installers in number of applications I have used.
Hope you can make your work easy by reading this :)
..installer for my java desktop application.
Deliver it over the net using Java Web Start.
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

Editing a .jar file with a .jar file

I have written an updater program for my friend to update another program I wrote for her as a going away gift. I have written all the needed code for retriving the class files that are updated from a server and holding them in temporary memory. What I need help with is having the program replace the class files in the first jar file so she doesn't have to do manual updates. Note: The main program is not running during update so no exploding jars.
So long as the app. has a GUI, deploy it using Java Web Start.
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation1 for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update2 (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
It is easy for the user.
Automatic update is built-in, all the deployer has to do is upload the new Jar.
If Java Web Start is not what you're looking for and if the jar executable is available on your friend's computer (either because a JDK is installed on your friend's machine or you distribute it with your application), you can run
jar uf jar-file input-file(s)
If you want to call the jar executable from within a Java program, just use Runtime.exec. For a more in-depth discussion about updating a JAR via the jar executable, see Sun Developer Network's article "Updating a JAR File."

Categories