How to create native binaries for your Java app? [duplicate] - java

This question already has answers here:
How can I convert my Java program to an .exe file?
(16 answers)
Closed 3 years ago.
I'm wondering how to package a Java application into a native binary for Windows, Linux and Mac OS X.
I know Minecraft does this, but I can't figure out how. This is what'd I'd like to do:
From NetBeans (preferably) or Eclipse, build the three binaries automatically.
Include native libraries for OpenGL et. all.
Obfuscate my code if possible.
If there's some way to mimic the Minecraft auto-updater feature, that'd be totally awesome.
So, are there any tools available to do this for you, or do I need to write a large bulk of XML to accomplish this?

To make a native binary for Windows, you would use a tool like Launch4J. On OSX you could use JarBundler. Minecraft simply distributes the jar file for Linux. I'm not aware of a native binary packager for Linux.
You could also compile your Java code via GCJ but that's probably not what you want, as there are limitations and compatibility concerns there. The native bundlers like Launch4j and JarBundler simply wrap your jar file and use a real JRE to execute it.
As for integrating with NetBeans or Eclipse, you'll probably have to write your own ant build file, especially since the solution varies from one platform to the next.

If you are using Java 9, you can also use Java 9 Modularization & jlink to ship a zero-dependency native app.
There is also maven-jlink-plugin that could help here.

Take a look at GCJBuilder plugin for eclipse. Not sure if it supports cross compilation as the command GCJ compiler does.

If the app. has a GUI and can be distributed from a web site, look into Java Web Start. JWS is supplied by Oracle, and provides auto-update amongst many other features.
Note that JWS uses Jar files, so no conversion is necessary.

I've used JSMooth for this in the past: http://jsmooth.sourceforge.net/
As mentioned before, this wrapper just looks for a real JRE to run it - it does not come with a bundled JRE.

Related

Is there a possibility to run a jar file within an android application with another jdk?

Im new to app development and was wondering if it would be possible to include another jdk. For example java 17 and run a jar that needs to be run in this exact version? I think termux has an api that you may use for these purposes but is there another possibility? These jars are only console based and without any gui.
I first tried to use the jar as a android library inside the app, which did not work since it was compiled in java version 17. I tried decompiling the jar and recompiling it with the version I was using. The problem is that all the libraries used are on other versions than I need them to be and so I could not recompile it. I also thought about writing the application in c# but I am not used to it at all, which would throw many new problems that I would be willing to take if it would be a possibility to work out my project.
Q: Is loading the code into your Android application an option?
A: No.
Android loads code from ".dex" files not ".class" files.
The ".class" files would need to be translated using dx.
The Android dx command doesn't understand Java 17 ".class" file format.
Also the code in the JAR is likely to depend on classes in the Java SE class library that the Android doesn't provide.
Q: What about running it in a separate Android VM?
A: No.
An Android VM requires ".dex" files; see above.
Also, the Java SE class library issue; see above.
Q: What about launching an OpenJDK or Oracle Java 17 JVM on the Android device to run the JAR?
A: In theory Yes, but in practice No. As far as I am aware, there is no port of OpenJDK Java SE to the Android OS platform.
Q: What about using Termux?
A: OK ... that might work. See Is it possible to install the JDK on an android device?.
I have no experience with this, and don't know what problems you may run into doing this. But I suspect that you wouldn't be able to distribute something that relies on Termux via the Google Playstore.
Another option is to download the source code1 for the application and try to build it in your Android dev environment
If the code uses Java classes / packages / libraries that are not available for Android, recode the relevant parts of the application to use Android equivalents instead.
Ditto if the code uses Java language features that are not yet supported in Android Java.
It probably won't be easy. It may turn out to be impractical.
1 - You said in a comment that the code your are trying to use is "open source". So the "download source and build it" option is available to you. I'm puzzled why you tried to decompile and recompile it instead ...

Compiling/packaging java programs into standalone executables?

I would like to deploy a java (or javafx program) which is usable even on a system that doesn't have JRE.
This question has been asked and answered:
How can I convert my Java program to an .exe file?
Compiling a java program into an executable
But those 2 questions are over 10 years old, and I'm wondering if there are any new/better options as of 2022.
There are some options you could choose from:
Bundle your JRE in your package
Eclipse does this for example. The put a JRE in the downloaded ZIP-File
The rise of the native images
Some projects start to do native java-executables. One is Quarkus. But the don't support JavaFx. Base technology for that is GraalVM
Spring is also starting native images: Spring-Native
Here is an example of a java-fx native image: Java-FX Native Demo
The tools to compile a JavaFX program into a native exectable can be found here: https://github.com/gluonhq/gluonfx-maven-plugin
Depending on your needs it might be also interesting though to just package your program for each platform via jpackage. Maybe following this tutorial https://github.com/dlemmermann/JPackageScriptFX

Creating .exe from Java for people to use [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I convert my java program to an .exe file ?
I'd like to create a Windows .exe for a Java program. Previously, I've used JEXECreator for this, but it's not entirely satisfactory because:
The executable sometimes works on the machine on which it was created but not on others.
The program is commercial; if you use the trial version, it adds a nag screen to your application.
I don't need the generated .exe to work if Java is not installed on the target machine (in fact, I think this is impossible).
Any recommendations?
Launch4j perhaps? Can't say I've used it myself, but it sounds like what you're after.
Most of the programs that convert java applications to .exe files are just wrappers around the program, and the end user will still need the JRE installed to run it. As far as I know there aren't any converters that will make it a native executable from bytecode (There have been attempts, but if any turned out successful you would hear of them by now).
As for wrappers, the best ones i've used (as previously suggested) are:
JSmooth
and
Launch4j
best of luck!
If you really want an exe Excelsior JET is a professional level product that compiles to native code:
http://www.excelsior-usa.com/jet.html
You can also look at JSMooth:
http://jsmooth.sourceforge.net/
And if your application is compatible with its compatible with AWT/Apache classpath then GCJ compiles to native exe.
I used exe4j to package all java jars into one final .exe file, which user can use it as normal windows application.
You could try exe4j. This is effectively what we use through its cousin install4j.
The Java Service Wrapper might help you, depending on your requirements.
If Java is installed on the target machine, there is no need to create an .exe file. A .jar file should be sufficient.

Java packaging tools - alternatives for jsmooth, launch4j, onejar

I have used these three open source tools for packaging my java apps, but they all look like abandon-ware now. All three are very good pieces of software. What are the options now? (or is using Java for desktop app development no longer a "hot" market for app developers to build & maintain these tools?).
1) exe wrapper:
jsmooth - no new development in 2.5 years - does not support 64 bit.
launch4j - no new development in over a year, supports 64 bit, but you can't sign the exe created by launch4j, so I prefer jsmooth, but it does not support 64 bit.
2) onejar:
It works, but there has been no new development or web site update in more than 2.5 years. So, just want to switch to something that's supported / have a backup plan if it suddenly breaks with a new build of Java.
Thanks
Edgar
Launch4j has just been updated ! http://launch4j.sourceforge.net/changelog.html
Did you check IzPack? This is a great piece of software to create cross-platform installers:
IzPack is an installers generator for the Java platform. It produces lightweight installers that can be run on any operating system where a Java virtual machine is available. Depending on the operating system, it can be launched by a double-click or a simple 'java -jar installer.jar' on a shell. The most common use is to distribute applications for the Java platform, but you can also use it for other kinds of projects. The main benefit of IzPack is that it provides a clean and unique way of distributing a project to users using different operating systems.
Some really famous companies and projects use it for many years (Sun Microsystems, JBoss/RedHat, the Scala language project, some ObjectWeb/OW2 projects, XWiki and many more). If it's good for them, it should be good for you :)
Since none of the answers were approved, and JavaFX 2.2 has not been mentioned above (was not available at the time of the answers) here goes:
JavaFX 2.2 (part of Java Runtime and SDK since 7u6) allows building native exe/dmg/rpm's that tag along the full RT component as well. I believe this is a valid answer to your need, as well as an officially supported solution from Oracle.
https://blogs.oracle.com/talkingjavadeployment/entry/native_packaging_for_javafx
Have you tried IzPack (http://izpack.org/)?
You can try
http://winrun4j.sourceforge.net/
Has an exe with 64bit support and is quite easy to configure with an ini file.
As I was fed up with recent security changes in Java Webstart, I created my own tool, JNDT. It's under GPL.
It goes farther than akauppi's suggestion because it allows to create GNU Linux packages even under Mac and Windows :) I use it to create Mac bundle under GNU Linux too. For the moment, it's just a single Ant library with a few dependencies that allows to create native self-contained application bundles for GNU Linux, Mac OS X and Windows. I use it for my first person shooter and I'm very happy with it. It bundles the JRE but it can use the system JRE if you want.
P.S: JNDT is able to create a native Windows installer as an executable with NSIS even under GNU Linux.
I understand that the GPL license discourages some developers to use my tool. In this case, rather use PackR.
Maven 2 provides the ability to create a jar which contains all the dependencies as part of its assembly plugin. This combined with the jar plugin configuration of the manifest file (and specifically setting Main-class to the Class with main) is all you need to do basic packaging.
To some extent Java web start is now considered the better way to distribute Java applications and Maven 2's assembly capability combined with web start gets you everything you need without going via the exe route.
If you just want an exe (instead of a full-blown installer) you can make one with NSIS:
http://nsis.sourceforge.net/Java_Launcher_with_automatic_JRE_installation
Yes, NSIS is an installer but you can have it just run a jar in the same directory by stripping out all of the installer stuff. Basically it works like launch4j but is a lot more configurable.
If you are using gradle, there is a plugin that uses launch4j (under the hood) and works great. It doesn't even require you to download or install launch4j, it is totally automated.
https://github.com/TheBoegl/gradle-launch4j

How do I create an .exe for a Java program? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I convert my java program to an .exe file ?
I'd like to create a Windows .exe for a Java program. Previously, I've used JEXECreator for this, but it's not entirely satisfactory because:
The executable sometimes works on the machine on which it was created but not on others.
The program is commercial; if you use the trial version, it adds a nag screen to your application.
I don't need the generated .exe to work if Java is not installed on the target machine (in fact, I think this is impossible).
Any recommendations?
Launch4j perhaps? Can't say I've used it myself, but it sounds like what you're after.
Most of the programs that convert java applications to .exe files are just wrappers around the program, and the end user will still need the JRE installed to run it. As far as I know there aren't any converters that will make it a native executable from bytecode (There have been attempts, but if any turned out successful you would hear of them by now).
As for wrappers, the best ones i've used (as previously suggested) are:
JSmooth
and
Launch4j
best of luck!
If you really want an exe Excelsior JET is a professional level product that compiles to native code:
http://www.excelsior-usa.com/jet.html
You can also look at JSMooth:
http://jsmooth.sourceforge.net/
And if your application is compatible with its compatible with AWT/Apache classpath then GCJ compiles to native exe.
I used exe4j to package all java jars into one final .exe file, which user can use it as normal windows application.
You could try exe4j. This is effectively what we use through its cousin install4j.
The Java Service Wrapper might help you, depending on your requirements.
If Java is installed on the target machine, there is no need to create an .exe file. A .jar file should be sufficient.

Categories

Resources