Creating a Linux executable file for my Java application Jar file - java

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

Related

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

Java application installer for MacOS

I'm new at Java for Mac developement and I spent a lot of time finding a way how to create an installer. It's strange but it's not too much information about it. All the ways lead to using of JavaAppLauncher. (I use appbundler-1.0.jar and Ant to build .app) But I faced a following problem.
JavaAppLauncher sets working directory to user folder. My application consists of several jar files, resources and configuration files. All of them located in Contents/Java inside the .app structure. I use relative paths to them, relative to the executable jar with Main class.
I googled 2 discussions only, where someone asked how to set the working directory inside the .app bundle. Threre is a way to sed -Duser.dir JVM option in plist file of .app bundle. I tried this and it behaves strange. When I use "new File(".").getAbsolutePath()" - it shows the directory I pointed in -Duser.dir parameter, but when I try to create file on disk or read file from disk - it still goes to the user folder as it was by default.
May be someone knows what is wrong there?
Or is there any better way to create a java application bundle for Mac?
Thank you, guys.
Use JarSplice to create OS X app bundle. Compile all your jars and resources into one jar file and export as mac .app file.
Deploying Java Applications can be a pain if your application has multiple jars and native libraries. There are the options of using Java Web Start or Java Applets however these are not always suitable.
Executable Jars are an option, however if your project has multiple jars or native files then it can be tricky to use this option.
JarSplice attempts to solve this issue by allowing you to merge all your jars and native files into one, easy to use executable jar file.
Features:
Creates a single executable fat jar via an easy to use GUI.
Automatically extracts only the native files needed for the OS the jar is running on.
Automatically cleans up any extracted native files after the application quits.
Add VM arguments on jar creation which removes the need to enter them via the command line.
Optionally create a Shell Script (.sh) launcher for Linux with embedded fat jar.
Optionally create an OS X App Bundle (.app) for running your application.
Optionally create a Windows Application (*.exe) for running your application.
This is the best cross-platform installer creator i have found yet. You can get the java executable from here

How to make an exe file to run in all systems which don't having JVM?

I recently developed an desktop application using java....i made .exe file using launch4j...
It gets executed on machines that have only JVM...
Propose me a way to make it executable on machines that don't have JVM
You can use Excelsior JET to compile Java into a native executable file on Windows that doesn't depend on the JRE.
Another solution could be GCJ
I use WinRun4J
You just copy the entire JVM to your program's directory and create an .ini file with contents similar to these:
main.class=com.program.Main
working.directory=.
classpath.1=.\lib\*.jar
vm.location=.\jre7\bin\client\jvm.dll
where jre7 is the directory with copied JRE.
Be aware that you need to check if you abide by JRE's licence.

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.

Have a Java application (JAR) that needs to be executable. (Built In Eclipse)

I have this little application (JAR) built in Java on Eclipse and it needs to be compiled into an executable file that people can just double-click and it runs. Ideally this would an exe filetype. I'm not so versed with java and what the needs are but I'm hoping it can be compiled to run one computers that maybe don't have java installed.
Is there any advice or direction you can point me to so I can figure this out?
Many thanks.
Ideally this would an exe filetype.
No, ideally this would be a Jar file. Just leave it be a jar file. It will work fine if you set up your platform to respond to double clicks correctly. And yes the computer will need to have Java installed -- that's not an onerous requirement.
Try this application : exe4j : http://www.ej-technologies.com/products/exe4j/overview.html
It runs on various platforms to made EXE files :))
You won't be able to make it run on PCs without Java installed.
There are plenty of guides on how to make an executable jar to run on computers with Java installed: take your pick: java executable jar creation, Make JAR as a standalone executable and so on...
You can try http://www.excelsior-usa.com/jet.html. It is free for non-commercial use.

Categories