Installer/packager for a Java application for Ubuntu and SuSE - java

I have a Java application complied to a collection of jars that I want to make installable on Ubuntu and SuSE. I Want the installer to be able to check for the JRE, register a file association and be able to load a website on un-install.
I understand Ubuntu and SuSE are based on different architectures, so is there a consistent way to do this?
Does anyone have an advice on utilities to use or guides to read to help me achieve what I'm trying to do.

Distributing a deb and rpm for each platform would provide IMO the best user experience and system integration (checking the JRE dependency, registering file association, etc). For debian based distro, have a look at Packaging Java Apps for Ubuntu (slides are available here). To build a rpm, have a look at the RPM Howto or Development and Packaging Java Software for openSUSE.
If you don't want to build packages for each platform, I'd suggest to distribute an installer, for example with IzPack. This tool allows to generate a unique cross-platform installer, provides native integration, is highly customizable, covers the uninstall part and the generation of the installer can be easily included in an automated build (Ant or Maven based). It's really a nice tool. And it has serious references (Sun Microsystems, JBoss/RedHat, the Scala language project, some ObjectWeb/OW2 projects, XWiki, etc).

Try with this. This installer works with most Linux Distributions.
Insert into a .tar.gz archive your jars. if you want Create a menu entry on Programs menu create a "YOUR PROGRAM.desktop" file and put this script into that
[Desktop Entry]
Comment=YOUR COMMENT
Name=YOUR PROGRAM
#(Must same as .desktop file's name)
Exec=java -jar "(Path to Extracted folder)/myapp.jar"
Terminal=false
Type=Application
Icon=(Path to Extracted folder)/myapp.png
Categories=Development
OK, Now you can put it into a .tar.gz archive too.
Now you have to create "install.sh" file (file name is not important, It also works without extension - .sh)
Here is the code
#!/bin/bash
if which java >/dev/null; then<
sudo tar xvfz YOUR PROGRAM.tar.gz -C /opt #(Path for Extract Files)
mkdir ~/.local/share/applications
sudo tar xvfz DESKTOP.tar.gz -C ~/.local/share/applications
echo "Program installed.!"
else
echo "JRE Not Installed..!"
fi
read
exit
Bring all 3 files in same folder, Then run install.sh file(Must marked as Executable)I hope that, This will be Helpful for any one.

You can use BitRock InstallBuilder, it allows you to crete GUI installers, RPM and DEB packages. It can do what you specified (file associations, launch web pages, etc.) It is commercial but we have free licenses for open source projects and discounts for small companies

If you don't want to alienate users, do whatever you need to do to let the user manage your package using the tools native to that distribution (see Pascal Thivent's answer). For Ubuntu and SUSE, this means deb and rpm packages.
As a user, I immediately get irritated whenever I need to install packages with their own installers.

Take a look at InstallJammer if you're looking for a GUI installer. Otherwise, you might consider building a separate, native installer for each platform. RPM in the case of SuSE and DEB for Ubuntu. InstallJammer can give you a GUI and also register with the native package manager on each of those systems if you wish.

I had the same need for packaging a Java app as a Debian/Ubuntu deb archive but didn't find a proper guide, so when I succeeded in creating a deb archive, I wrote a guide of my own.
Basically, what I did was create a Bash script that arranges .class files, etc. in a file hierarchy ready for a .deb archive, writes an executable script to launch the packaged program, handle .desktop file for GUI handling, and then run dpkg --build on the whole thing. Also, an important step, run lintian -i on the resulting .deb file to make sure you're adhering to all standards and policies.

Related

jpackage install to directory with read/write/excecute access on linux?

On windows, you can achieve this by using --win-per-user-install and the msi installer installs to directories like %LOCAL_APP_DATA%/<app-name>. This directory has read write access for other programs by default. I want to use the equivalent for linux. So what is the equivalent for %LOCAL_APP_DATA%/ for linux, having read write permissions by default, and how do I tell jpackage to make the installer install there?
I am packaging a jar file which manages the update of the application's files and installs them from the server. All this is done in the same directory where it is installed. I cannot change the code in this jar file, so any java code solutions can't be done. I need to achieve this using jpackage.

Izpack executable jar to RPM

I'm trying to create a rpm package for an executable jar generated using izpack. It's basically an installer wizard that allows a user to install a tool/software. It provides an executable jar. So we have to do
Java -jar file.jar
To initialize the wizard. I'm trying to automate it in Linux by creating an rpm that takes this jar and an sh file that executes this jar and runs the sh file when I execute the rpm file. I'm new to rpmbuild and all the tutorials online are about copying a particular jar from the rpm file to a target location not about how to execute it.
Can someone provide me a sample spec file which does the following
Creates an rpm file with .jar and .sh
When rpm -i file.rpm is executed, it runs the .sh file which in turn executes the jar and opens the wizard.
I'm open to any other suggestions on how to make jar auto execute. I'm basically trying to create an exe similar file for linux
Thanks in advance.
I highly recommend not doing this for various reasons, because it is the exact opposite of what RPMs are supposed to do. You should instead do the installation process on a build machine (as a non-root user!) and then capture the files to be installed.
Why is your approach a bad idea?
Installation script is hidden from the user (they cannot just query the RPM scriptlet to see what changes, beyond files, you made to their system)
The final installed files won't be controlled in any way, e.g. you won't be able to verify if they had been corrupted (rpm -V) or query what package installed them (rpm -q --whatprovides /path/to/file)
"Removing" or "Upgrading" the package won't actually do anything unless you write detailed scripts to handle all these unknown files
All the other reasons I didn't list as why you use a package manager instead of blindly distributing tarball distributions like we did in the dark ages
That said, if you insist on breaking things, your solution is to put the java installation call in %post, which will execute after the files have been installed. It will call it again when you upgrade the package, so the other installer needs to handle that. But again, this is not the right approach.

Cross-platform Executable Questions (avoiding duplicate)

I know that windows users prefer .exe (Windows EXEcutables) and mac users prefer .app (AppleScript application) and Java uses .jar (Java ARchive). But is there any reasonable cross-platform executable because to execute JAR you need the CMD or Terminal (at least in the case of a Mac) to run the file by using:
java -jar %FILEPATH%
But is there any other executable I can use?
Should I just have a Mac and a Windows downloads?
Can I make a jar that can be double clicked?
I have searched as far as I can in stock overflow but no simple reasonable answer.
Hope this can help more people than me :)
To be able to start a jar file via double-click, the .jar extension needs to be associated with the Java Runtime executable, javaw.exe under Windows. That is the same mechanism used to open for example .docx files with Microsoft Word.
As far as I know, the JRE installation adds such an association automatically.
In order to tell Java which class to start from the Jar after it was double-clicked, you need a META-INF/MANIFEST.MF in the Jar, like #Elliott Frisch described.
By the way: Mac apps are in fact folders, which Mac OS X shows as one piece (right-click on a Mac app and click Show Package Contents to enter that folder). So the idea is very similar to Jars, although Jars are real files and not folder -- and of course their format is totally different.
So a Jar is the format "executable" on all platforms (having a JRE installed).
An executable JAR file is the most portable cross-platform executable. Macintosh app files are Mach-O format, and not compatible with Windows Portable Executable. The Windows executable format is not compatible with Mac or Linux (ELF). Basically, the only format that will reliably run on Windows, Mac and Linux is a Jar File.
From Setting an Application's Entry Point the Java Tutorials,
If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application's entry point. You provide this information with the Main-Class header in the manifest, which has the general form:
Main-Class: classname

How do I create an Installer for a Java Application?

This is still awhile down the road for me but for my Project Implementation class we have to create a program and then distribute it. I have written an application in Java and from the specification I have made in the previous class (Project Design) my application will need to be platform-independent.
For mac and linux the user can just run the jar file from the terminal, but for windows I would like to have the Application installed to the path user chooses (default: C:\Program Files(x86)\NameOfApplication), Create a desktop shortcut (if the user wishes to have one), install under the start menu (if the user wants it to) and then also show up in the add\remove programs list.
Is there any easy way to do this?
Is it any harder if I did decided to create an installer for mac and linux?
Thanks in Advance.
You can create an installer with NSIS, even for a Java application.
You might also consider distributing your application via Java Web Start.
There are opensource installer generators for java. I have never used one before. Here is a good resource of links
I recommend using Java Web Start.
It has several advantages.
Available for all major desktop platforms
Single distribution for all JWS-enabled platforms
Code-signing and sandboxing
Versioning and incremental updates
Automatic installation of JREs and optional packages
It has one major disadvantage.
Internet connectivity is required if JWS, JRE, and/or an Optional
Package is not present on the system
Have a look here and here
Install4j does what you want, although you have to pay for it. Personally, I am not aware of any free alternatives. You can make installers for Linux and Mac OS as well.
you can use Exe4J, see http://www.ej-technologies.com/products/exe4j/overview.html
You can do most of that using standard JNLP:
http://docs.oracle.com/javase/1.4.2/docs/guide/jws/developersguide/syntax.html
You make a JNLP file that takes the executable JAR from some local (or remote) location and creates a Desktop icon for it (of your chosing). Only difference is that the actual JAR will be placed in the JDK's jar cache directory (not in a directory of your choice - I don't think the user would care much).
The huge advantage with this is that if you make a JNLP that installs the jar from a remote location, you can remotely upload a new version of the jar to that location, and when the user next accesses the jar locally, your latest version will be downloaded and placed into local cache.
Also I recommend you use a smart "fat JAR" builder, which packages all dependency jars inside the executable jar. Eclipse IDE has a way to export a project in this format (and also adds the necessary class-loader so that all works ok from on fat jar).
If your target OS is windows I highly recommend Advanced Installer. It's very very easy to use and will let you create your own native microsoft installer (.msi) with specific target Java VM and a bunch of useful windows features, even in the free version. Note you can also include a private jre into the package.
http://www.advancedinstaller.com/top-freeware-features.html
If you want a "package one deploy everywhere" solution then IzPack is the way to go, platform independant, free and open source.
http://izpack.org/
Depending on the complexity of your project Java Web Start could be a very good option, it's very simple configure and maintain but it relies on the browser's java plugin and believe me... most users DON'T like being warned about certificates and risks everytime they launch an application.

Java application installer for linux

How can I create a linux installer for java desktop application? for an instance if we want to install netbeans on ubuntu there is a download which is named as "netbeans-6.8-ml-java-linux.sh" so how can i create "mydesktopapp-linux.sh" i have the properly working .jar file i want to distribute my java desktop app. Can anyone help me?
I recommend you to have a look at IzPack. IzPack is a one-stop solution for packaging, distributing and deploying applications.
It is fully cross-platform and generates a single installer. As such, it is an alternative to native solutions such as platform-specific installers and package managers.
There are many other alternatives, but IMO IzPack is as good as they get and is completely free. If your app targets only Unix/Linux hosts you might consider creating native packages like RPM, DEB, etc...
simple..
open the .sh file,
type ..
java -jar myJar.jar
now doubleclick the .sh file to run ur application
On Linux/Unix, the *.sh suffix identifies a shell script. These scripts are simple text files, starting with the special #! notation on the first line, which specifies the shell that will run the commands in the file.
Like the netbeans-6.8-ml-java-linux.sh you mentioned, your script should start with #!/bin/sh to reference the Bourne shell.
As mentioned already by raj, a simple
java -jar myJar.jar
command could be the minimal contents to launch your app from the jar.
You can then make your launch script arbitrarily complex in order to deal with different locations of the java executable, handle insufficient permissions, providing nice help messages, etc. (again, have a look at netbeans-6.8-ml-java-linux.sh to see what I mean).
You should take a look at InstallJammer. Not only can it build a cross-distro installer that would be easy for newbies to use, it can also register itself with the native RPM or DEB package manager so that the user can uninstall through the common system.
Introduction to shell archives
http://linux.die.net/man/1/shar
http://www.rpmfind.net/linux/rpm2html/search.php?query=sharutils
This might work for you as well:
makeself - Make self-extractable archives on Unix
makeself.sh is a small shell script that generates a self-extractable tar.gz archive from a directory. The resulting file appears as a shell script (many of those have a .run suffix), and can be launched as is.
http://megastep.org/makeself/
In addition to makeself and the other tools mentioned in the thread, I suggest taking a look at my tool, BitRock InstallBuilder It is capable of creating self-contained executables that can be downloaded and launched but unlike some of the other tools do not require a self-extraction step. That means the installers start faster and no extra disk space is wasted. It is commercial, but reasonably priced (and we have significant discounts for solo developers and smaller companies)

Categories