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.
Related
I found that Packr is the best tool to use for creating an executable file for my Java application on Linux. The executable works perfectly on Linux, but i have a question about this tool:
The tool forces me to embed JRE with the output folder causing big output size for my application. Can i create the executable without embedding JRE with it?
If you are using java 9 or above you can use jlink to create an image that only contains the required jre modules and therefore will likely give you a smaller distributable. There's a tutorial here
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.
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've my JavaFX app that calls some JNI code, uses a preloader jar and is compiled using jdk 1.7.
Now when I run jar on another computer with JRE7, by:
Double clicking jar: it starts but cannot load the JNI code containing libraries and therefore gets stuck.
Running jar via terminal using "java -jar ": App runs completely normal!
Now if I install jdk on this machine,
it runs fine even with double click!
Can somebody tell me what is difference in these 3 cases?
Try to add logging to your program, so that you can figure out why your JAR file doesn't execute properly.
You should look into if your manifest file is correct - there is a classpath in there you might want to take a look at.
This may have something to do with the fact that JavaFX is not fully released with Java 1.7, but included more as a developer preview.
Also, JavaFX packaging and deployment is a little different than standard Java. There is a new utility called 'javafxpackager' that should be used when packaging JavaFX applications. Check out the documentation here: http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm
Is it possible to create a stand alone application in Java (using Swing) and package it into an exe file?
My Idea is, we should be able to double click it and run the application.
If you export a runnable .jar file you will be able to double click and run, but you'll still need the JVM in order to interpret the bytecode.
The best way to deploy a Swing based app. to a client's desktop is using Java Web Start.
JWS offers desktop integration - making a desktop shortcut and menu item, each using an icon if specified. The end use can double-click the desktop shortcut cut to launch the app. ( or single-click the menu item to do the same ;).
Best of all, JWS works for all platforms for which the J2SE is supplied. Windows, Ubuntu, Fedora, Solaris, Mac. OS..
For ensuring the user has the correct minimum JRE needed to run the app., use deployJava.js to write the link to the JNLP launch file.
If you export your project in a .jar file, you will be able to run it when you click on it.
I suppose that you know that you must have the virtual machine installed in the computer that runs the program.(The virtual machine is the thing that allows java to be operative system independent)
And also you must know that if you transform that .jar to an .exe file using some kind of gadget... Then java will not be java anymore, because will not be able to run it in non-windows operative systems.
Remember java slogan
'Write once run everywhere"
See this image here i will explain you how to create a .jar using the eclipse IDE:
1-Select your project in the package explorer
2-Select File>Export from the menu
3-Pick Runnable JAR file from the dialog and
4-Click next and follow the rest of the wizard
You can package your application to JAR file. Application in jar file runs on duoble click.
Here is tutorial. http://download.oracle.com/javase/tutorial/deployment/jar/
You can already do this with a normal .jar file if the user has configured the extension to be executed with the JRE. But you can always use something like Launch4J. Please Note this simply wraps the Jar in a EXE file. The file still needs your Dependencies (.jars) and the JRE enviroment.