How do i compile .jar with jre? - java

I have a friend without java. I want to package my executable .jar file with java platform SE binary in an exe file so he can run it without downloading the entire java runtime. Could someone point out some kind of software that does that?

I have a friend without java.
And you call them a friend? ;)
Use deployJava.js to check the user has the minimum Java required to run the app.
Install & launch the app. using Java Web Start.
Give the user a link to the 'launch' web page.
This will work on Windows ..and OS X ..& *nix.

Try using Launch4J at http://launch4j.sourceforge.net/
Here's the highlights:
Launch4j wraps jars in Windows native executables and allows to run them like a regular Windows program. It's possible to wrap applications on Windows, Linux, Mac OS X and Solaris!
Also creates launchers for jars and class files without wrapping.

I have also had good experiences with Launch4j. Also check out JSmooth: (http://jsmooth.sourceforge.net/index.php) which claims to have an option to download and install a JVM if one is not available.

Related

create executable .exe file from javafx project with JRE

I have a JavaFX project and I'm trying to get an executable exe file from it. I use launch4j and Inno setup wizard technologies for it. My exe file works only in computers which have java in them, but doesn't work in computers that don't have java installed.
I want to create exe file so it includes JRE, so it works in all computers.
I am showing how I do it in this video
Please help me understand what I'm doing wrong. Thank you.
In java8 you can use "Javapackager". You don't need launch4j or innosetup.
Additionnaly From version java 13 (available in early-access) there is a tool named "jPackage" with which you can create an msi, exe, deb or rpm depending on your OS and options. But there will be a little difficulty, because javaFX is no more packaged in the jdk, and you need a module declaration to make work the tools chain (jlink then jpackage)
It's a lot of work to upgrade your project from 8 to 13, but it could be usefull for later consultation of your question:
see https://openjdk.java.net/jeps/343

My program requires java JDK to run?

this is a kind of weird non programming (but java related) question.
I created a java program (game) using just normal java, and no libraries.
In ordor to double click/open it, you need to have java SDK/JDK (I don't know which) installed.
I tested this multiple times, and in order for my PC and Mac to launch it, you need to install it.
is there anyway to get around this? I know Minecraft doesn't force you to download the JDK.
Here's the link to source code of my game if your interested (no, it is not a virus): http://www.filedropper.com/daplatform
Thanks, Jake
Here's the link to the download of the JDK (Its next to the giant Netbeans download): http://www.oracle.com/technetwork/java/javase/downloads/index.html
What you can do is you can wrap both your program and the JRE required to run it into a single executable for the target platform.
For example your windows installer would include both a windows JRE and your program itself.
Launch4j http://launch4j.sourceforge.net/ lets you wrap a Java program into a windows executable and gives you options about how to handle the JRE, including bundling it.

How to install JRE while deploying a Java Swing application?

I'm new to Java Swing & I'm a bit stumped. The application I'm developing will be installed on systems that have not installed JRE. Is there any way to pack JRE inside the Java Swing application and create an EXE file which installs JRE and the application?
Use deployJava.js to ensure a suitable minimum JRE is installed on the computer of the end user. Then use Java Web Start to install and launch the application itself.
Both of those are:
Supplied by Oracle for deployment of rich client apps.
Designed to work on Windows, OS X & *nix.
You can create .exe files from your Java program source using Launch4J. This tool offers an option to set up a relative path to a Java JDK/JRE. This means you could deliver your software with the needed JDK/JRE.
But be carefull. I think you get in trouble if you offer a JDK/JRE for download due to licensing issues.
Best way is to tell the users to install JDK/JRE themselves....
You have to use an installer for that. Try NSIS for instance

Java exe launcher with support for Windows 7

The Problem
Currently I use exe4j 4.4.2 to wrap our client app in a Windows native executable, but the result does not integrate with Windows 7 so well.
For example: When I right click in the task bar it only offers a pop-up to close the application but no pinning. Eclipse' Equinox launcher on the other hand does that with bravado.
I'm looking for a java exe launcher which has the following features:
Wraps jars in Windows native executables (no Java Web Start or similar)
Doesn't extract the jar from the executable
Doesn't need write access in "Program Files"
Uses executable filename as process name (only one process)
Integrates well with Windows 7 (esp. pinning in the taskbar)
Allows setting of JVM arguments (esp. heap size)
Flexible customization for JRE search
Lightweight
Actively maintained
Integrates well in Ant build
Preferably free
I have checked the following:
exe4j
Windows 7 integration lacking
It's not expensive but ordering and
distribution of licenses to the build machines is a pain.
JRE search not flexible enough
Eclipse Equinox
Not lightweight
Seems to do everything I want, except that I have no idea how
to use it with a non-eclipse-based app.
Can I use it outside of OSGI, PDE-Build world?
WinRun4J
JRE search not well documented
Seems not widely used despite incredible feature set, what am I missing?
Launch4J
Doesn't support setting the process name in Windows 7 (Bug ID 3353972).
There is a patch (Bug ID 1670471) but it has been rejected with reference
to jliftoff which is dead.
JRE search not flexible enough.
JSmooth
Seems not to be actively maintained.
Latest release is from 2007, well before Windows 7.
Are there any other options?
Is there a chance to use the Eclipse launcher with a non Eclipse-base application?
Try Advanced Installer http://www.advancedinstaller.com/java.html (There is a free edition available in this).
I'm happy with WinRun4J. The JRE search works fine for me. It sometimes chokes especially on 64bit systems if multiple JREs and JDKs are installed and registered in the Windows registry, but this can usually be fixed by supplying the correct path in the corresponding .ini file.
I did not use Launch4J because it creates a new (temporary) .exe in the JRE installation folder which seems a bit strange to me. The advantage of that method is, that it can use a single .exe for both 32 and 64 bit JVMs though
It sounds to me like you just need to go with Launch4J. The process name matches the .exe name that you launch with. A great example of a program that is wrapped this way is "Keystore Explorer 4.01".
I would create a bat file. Wrap this bat file into a exe. You can create an exe with an icon and everything. Try this bat to exe converter:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
In this way, you have better control. The size of the exe is very small.
Edit: Also, the creation of the exe is one time thing.

How can I create a Windows .exe (standalone executable) using Java/Eclipse?

I'm new to the programming scene. Been working with C++ for about 5 months now, and have decided I want to start getting into Java. I'm using Eclipse as my IDE, and obviously Java for the language. I'm trying to write a simple HelloWorld application, which can be run through a command prompt executable.
In Visual Studio, it seems it's rather easy to create an executable. All I've ever had to do is use a pull down arrow and choose Release, and then run my build. The purpose of wanting to be able to write/run Java in command prompt is so that I'm able to practice some of the language basics before I go in full force with Swing.
So bottom line, what is the easiest way to create a command prompt .exe written with Java?
Thanks in advance!
Java doesn't natively allow building of an exe, that would defeat its purpose of being cross-platform.
AFAIK, these are your options:
Make a runnable JAR. If the system supports it and is configured appropriately, in a GUI, double clicking the JAR will launch the app. Another option would be to write a launcher shell script/batch file which will start your JAR with the appropriate parameters
There also executable wrappers - see How can I convert my Java program to an .exe file?
See also:
Convert Java to EXE: Why, When, When Not and How
Creating a native installer using jpackage
A java packaging tool named jpackage was released as part of the Java Development Kit (JDK) version 16.
This tool works in conjunction with native packaging tools for various platforms (e.g. WIX for Windows, RPM, and DEB for Linux distributions, DMG for Mac) to allow building native installers for Java applications which can then be run as executables. For distribution, it may be possible to distribute just the executable for the application, independent of the installer (I don't know, I didn't try that).
A nice, tutorial style, blog post that describes the use of the jpackage tool to create a native Windows installer for a Java application is:
How to create a Windows Native Java application (generating .exe file)?
Customizing the runtime image using jlink and jdeps
The packaging tool can (optionally) be combined with the jlink tool:
jlink - assemble and optimize a set of modules and their dependencies into a custom runtime image
This allows you to customize the runtime image for your application to only include the required custom selected modular parts of your application code, java runtime, and 3rd party libraries, rather than distributing a complete java runtime.
Optionally, you can also use the jdeps tool to determine inputs to jlink.
Complete discussion of usage of jdeps + jlink + jpackage + a native bundle creator (e.g. wix/rpm/deb/dmg) is outside of scope for a StackOverflow answer, but various resources can be found on the web if you search.
Creating a standalone .exe instead of an installer
This can be done using warp-packer to create a exe out of the image and app launcher created by jlink.
How to create a standalone .exe in Java (that runs without an installer and a JRE)
Third party tools can help deliver a solution
If you wish to use all these tools in combination, things can get complicated, and I'd advise using a 3rd party utility or template to help perform this task. For example:
badass-jlink-plugin (documentation) -> "allows you to create custom runtime images for modular applications with minimal effort. It also lets you create an application installer with the jpackage tool."
For JavaFX specific applications (as your question has a JavaFX tag), you could review:
JPackageScriptFX -> "demonstrates how projects can use scripts to build self-contained, platform-specific executables and installers of their JavaFX applications via the jdeps, jlink, and jpackage tools."
For native mobile deployments, see Gluon Mobile
This question was Windows specific, but for completeness, if your target is native application deployment on a mobile device, then likely you will need to use a 3rd party solution such as Gluon Mobile.
Background Rationale (ignore if not needed)
creating a native installer using jpackage might be a bit of work, so why would you do it?
Here are some reasons:
When an application is distributed via an installer created using jpackage, that application can be installed on a target system without requiring the user to manually install other dependencies (such as a Java Runtime). The installer will take care of ensuring that your application and any dependencies it requires are installed.
The application ships with its own customized version of the Java Runtime. This means that if the user doesn't install a JRE, and, if they have installed a version of the JRE which is incompatible with your application, your application will still function correctly.
The application can be installed and uninstalled using standard OS facilities for the target platform. Most users of those platforms are familiar with these.
Yes, Java is cross-platform for the most part, but many users don't care much about that, instead they just want a smooth and familiar installation (and uninstallation) experience for their application and jpackage can help accomplish that.
Typical Java programs compile into .jar files, which can be executed like .exe files provided the target machine has Java installed and that Java is in its PATH. From Eclipse you use the Export menu item from the File menu.
Creating .exe distributions isn't typical for Java. While such wrappers do exist, the normal mode of operation is to create a .jar file.
To create a .jar file from a Java project in Eclipse, use file->export->java->Jar file. This will create an archive with all your classes.
On the command prompt, use invocation like the following:
java -cp myapp.jar foo.bar.MyMainClass

Categories

Resources