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.
Related
Recently I developed a jar file with JavaFX. Now my problem is how to convert it into an executable so it can install and run on other systems which do not have any JDK installed.
Also, when the client system starts from shutdown or hibernate I'd like the executable to run automatically.
I searched a lot on Google and I found content on the internet, but I did not find how I can achieve this.
how I can convert it into exec with the install so it can install into other systems which do not have any JDK on that system
You always need the JRE to run the jar file, there's no way around that. However, since the assumption that almost all systems would have the JRE installed is no longer correct, the normal thing these days is to bundle the entire JRE with the installer and use launch4j to create an exe file.
and another thing I want is that when client system start from shutdown or hibernate exec should run automatically.
You can't do this at the Java level, so it depends what OS you're running on. On windows you could use sc.exe to create a windows service from the executable, or you could just put it in the relevant user's startup folder.
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.
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
I try to convert a jar file to an exe file.
I followed the instructions provided here using launch4j .
I get only an XML file but no exe as expected.
Any ideas?
So how should I deploy my application?
Your user would have to have the JRE installed on their computer. However, you could also distribute java.exe and rt.jar (the java run time jar) as well as any library jars you need for your application along with your program. Since the java command has an optional classpath parameter you could write a batch file (something like runme.bat) which would look something like this:
java -cp rt.jar;myapplication.jar;otherjars.jar MyMainClass
This is still Windows specific because the java.exe file would be a Windows specific file. You could also add in logic to check for the environment variable JAVA_HOME and if that's set on the user's computer then the java program specific to their OS would be in JAVA_HOME/bin
Your real problem comes when you're not sure what operating system your user will be using AND you don't know if they have Java installed. If you simply require that the user has the Java Runtime Environment installed then you're problem is solved for all users.
I hope that helps.
Greg
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.