how to create exec with installer and automatically run file - java

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.

Related

running java installer with bundled jre

We currently ship a java(jar) installer of our application. Taking into acount the changes to jdk11 we want our users to have the same easy install experience. So, what we are looking for, is to have just one file that can be run even if there is no java installed, it should just start our old java installer.
Probably, this means that we jave to bundle the jre and have a script that runs the jar, but the problem is how to run the batch file natively ? We need this to work on Windows and Mac. Most tools we are looking into require java to run the wrapped jar.
You have to build 2 different scripts/installers, one for each platform. Even looking at very popular software like Chrome, the platform choice is still there (even though you're usually directed to the correct choice based on the information your browser provides them with)
Depending on how much time you can put in this task, the quickest (and dirtiest) solution would be having an archive for each platform that contains the script .bat for Windows and .sh for OS X together with the jre (also different per platform), ask the user to unarchive and run the script which will run your jar with the packed jre. Otherwise, you'll need to create an MSI/exe for windows and a dmg (or other installer type) for MacOs.
I have done the dmg before with a bundled jre and can try to look for the details if you need them (I no longer have access to the code but can probably find the details). It was a free solution but it did require an OS X computer to create the dmg.
One option that I used before and works very well is install4j but the price is not small.
LE: Self contained packaging - although I haven't used this before, it seems like the best current option for your problem.
And an open source option - packr.
that Self Contained packaging doesn't really help, same for packr, same for launch4j. Because all those just generate a application image with a lot of files and directories.
Problem is before that, as an installer you want 1 big exe (or dmg for mac) that does it all, single click
We are already at the stage like SCP or Packr. Because that is easy or current installer.exe and jre\ sub dir and a batch/sh file besides it. Problem is how to get from that directory structure to a single exe that runs.
So what we should have is something that can zip that in a self extracting archive, when clicking on that it should auto extract to the temp dir of the OS, then run directly a command on it (like a batch file or directly in that extracted dir: .\jre\bin\javaw.exe -jar installler.jar)
But nobody seems to have made such a thing, the closest that we have is eclipse with Oomph:
[1] https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.extractor/src/extractor.c
[2] https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.extractor.lib/src/org/eclipse/oomph/extractor/lib/BINExtractor.java
problem is a bit that is doing the extracting through java and still wants a vm first.

Netbeans 8.2 not appearing in registry or allowing itself to be associated with files

I have installed Netbeans 8.2 and jdk and jre 1.8.0_171. (Windows 10 OS; on a clean installation of the OS btw, just to eliminate possibility of corrupted registry keys, viruses etc).
I believe I have correctly set the system environment etc.
I created a HelloWorld file in notepad; compiled on cmd line, then when tried to run the file, I was asked as to what (default) program I wanted to use to run it.
When I went to associate netBeans I was unable to do so because it does not appear either in the menu, or in the control panel file association facility.
Even more odd, is when I went to check the registry,
Computer\HKEY_CLASSES_ROOT\Applications
netbeans was not there.....
Netbeans itself btw runs and works absolutely fine, so I am rather baffled by this....
Please advise
If you are running a Java application from the command line in Windows then you should be using java.exe to run it. NetBeans is an IDE, and while it does provide functionality to allow Java to be run internally (i.e From within NetBeans), that is very different to using NetBeans directly to run a Java application.
Furthermore, NetBeans does not use the Windows Registry for application registration, which is why you cannot associate NetBeans with any file type. Just because NetBeans can be installed as a Windows application does not mean that it is required to implement all the possible functionality of a Windows Application, such as file association.
It's also worth noting that the beta release of NetBeans 9 is only provided as a zip file, and its installation consists of nothing more than unzipping the dowloaded file to a folder, so it definitely does not use the Windows Registry.

How do I make an installer for my java program which also installs mysql?

When the program is installing on windows, I want the installer to check if mysql is installed, and install it if it isn't (Or at very least give a link to the website so the user can install it)
I'm sure this is possible, I've been trying to figure this out for a while now. If you can have an installer check if the user has java installed and install it if they don't, then surely you can do the same for mysql?
Perhaps I'm looking at this the wrong way - should I instead be getting the java program to check if mysql is installed and install it then if it isn't? And if so, how do I do that?
Any help would be hugely appreciated, I've been stuck with this for a long time.
I refer to this answer.
Java is cross platform, MySQL isn't, so you'd have to create various installers for multiple platforms with different MySQL binaries.
My suggestion is to have a look around the web in order to find the correct way to create an installer depending on the OS you're using
Installer is usually created for OS (Windows, Linux). In our case we created deb package (for Debian) which checked if PostgreSQL and other prerequisites are installed and installed what is missing. So, basically it is job for installation script (in our case it was shell).
Wix installers along with .bat files you can use.
http://wixtoolset.org/
It has built-in directives that can check if software is installed or not, outdated version notifications also.But WIX is kind of a database of your software binaries.So you have to include the binaries of MySQL(whichever are supported on windows) in the installer using harvest wix utility.
http://wixtoolset.org/documentation/manual/v3/overview/heat.html
This will just copy the binaries in your target directory if the software is not installed, you have to write all this logic to skip or install using wix directives/conditional custom actions .To do after copy stuff like starting or configuring the service either write a bat/powershell file which will handle all this and you can invoke this powershell file from wix after the copy action using wix custom action directives.
http://wixtoolset.org/documentation/manual/v3/wixdev/extensions/authoring_custom_actions.html.
Or you can write all the steps of bat files in many different custom actions.You will need visual studio to create this installer.In the begining it will be trouble to understand how it works but this is the best way to create production level deployment/product installers for microsoft suite.

What is difference between executable and install able jars

I am developing one desktop application in javaFX. I am using in memory database hsqldb. I want to make this application to run on any windows machine by just double click or by installing.
I have gone through the launch4j library, using which I can make .exe file of my jar.
But if I create the .exe file, then I can open this application by just double clicking on it. anyone can copy and paste and open it.
I am confused with install word here.
What extra things will happens, if I want to make my application installable. Because I want to give an expiry date my application.
The answer to your question lies on the description of launch4j on their site.
The executable can be configured to search for a certain JRE version
or use a bundled one, and it's possible to set runtime options, like
the initial/max heap size
Not every machine you distribute the jar to may have a JRE. A bundled JRE will help the launcher run your jar if a JRE cannot be found on the target machine.
If you want to force updates on your jar, consider running a plugin mechanism or forcing the user to download a new version. It sounds to me like a web application might suffice instead ?

Executable jar and double-click

I'm in the process of creating a fairly extensive desktop application using SWT. To generate an executable jar file I use maven-shade-plugin in version 2.1. After generating a file, typical double-clicking does not work (the system tries to open a few seconds and stops). Calling from the console
java -jar pakiet.jar
works very well.
Previously, I created a project with SWING with using the same plugin and double click worked without a problem. Is the problem may be to use SWT?
Java version 1.7.0_25
OS Windows 7 Professional x64
You can create a *.bat file with the following content:
start javaw -jar pakiet.jar
I've been using launch4j my my SWT applications, works really well. You can even bundle the jre to avoid any dependencies on the target machine. Supports a splash screen, icon for the exe, you can enforce single instance of the exe, min/max jre versions, graceful error message if jre not supplied etc etc.

Categories