Wrap a executabe jar into .exe for using without jre installed - java

I would like to wrap an executable jar into a .exe file in order to give it to associate. I used Launch4j and it works. However the others are not able to use it. Error occurs always with Java version.
I found this question:
Running a java program as an exe in Windows without JRE installed
Is there nothing else more easy to use?
EDIT :
I slected prefer JRE rather than preferJDK und JRE window, that was the problem there.

In Launch4j, under JRE > Bundled JRE path, type something like ./runtime. When you wrap your JAR file into an EXE, the EXE will look for a java runtime in the current directory under a subdirectory called "runtime". If you copy a Java runtime directory into the same directory as your wrapped EXE file, it will use it.
In Windows Explorer:
The "runtime" directory is the complete JRE directory, E.G. "jre1.8.0_201", but renamed. Inside there should be a bin folder and a lib folder and some other files.

Related

Fails to run a Jar file on macOS using Zulu JRE (8.271)

java -jar jarfile works perfectly on Windows/Ubuntu, yet on macOS, I keep getting "Could not find or load main class."
Not only that, when I run the jar using Oracle's JRE - it works (the oracle's JRE isn't part of the path, so I write the absolute path in order to verify the right version I'm running).
So using absolute paths to the jre\bin\java files, once to the Oracle's JRE (works), once to the Zulu's Mac version JRE and I get "Could not find or load main class."
Any idea?
I used a simple java -jar jarfile command.
The Manifest file in the Jar does include a Main file reference (an obfuscated Main file) yet has no reference to a classpath (we wrap everything inside one JAR so we don't have any external jar dependency).

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

confused with Java EE exe and jar

In the existing projects where I'm working I see that there are Java EE jars like j2ee-1.3.jar existing, but when I try to download from Oracle website (1.6 version) I only see .exe available. So how are they connected, is it like exe after installation will create jar in the installation folder?
I checked the contents of exe with WinRAR but could not find any jar.
Also I have the same question regarding exe of JRE and adding it as external jar to eclipse project.
I suppose you are talking about the JDK installation executable file... So yes you guessed part of the answer, the JDK installation file for windows systems is an executable file that will do nothing but downloading and unpacking the JDK/JRE which is a set of java libraries jars (which you use for your development) in some directories you specify in installation steps.
This is the mains ubject of you question, but note that you will not only find jars when browsing the JDK installation directory, but a lot od other bunch, mains to be cited:
The java process uses for runnig your application.
The javac binary file used for code compilation... and many other staff
.jar is a library /package of Java and when you are on oracle to download it's application of java i.e. jdk or jre.
So when we do programming jars are used to add functionality, we will have to import classes from it.
when we want to use external classes then we have to use it's jar file.
when we do any import like import org.springframework.beans.factory.annotation.Autowired; it came from jar or dependency.
You can make executable jar file of java program, you can find out tutorial for it online. so whenever you click on that executable jar file in any machine where jre is installed you can access it. This is called Executable Jar, and you are telling about Java EE exe is setup application for New Fresh Java Installation.

jar to exe convert problem

hi i converted my jar file into an exe using jsmooth but when i install it, it shows an error like java not found.
Please help me, how can I add the jre to my exe wrapper so this problem is solved.
It is trying to get the java installation to run your application, where it might be searching in JAVA_HOME, So if the JAVA_HOME is not set in the machine where you installing your application then try to install the java and set the JAVA_HOME as a pre-requisite of your installation.
I don't believe JSmooth can actually bundle a JRE with the exe. What you can do is tell JSmooth where to expect the JRE when running the exe (as in the same folder the exe is run from). If you do this you simply need to zip the exe and a JRE up, and distribute that.
The end user would unzip this, and the resulting folder would contain your exe and the JRE. Since JSmooth knows where to look relative your exe, it can find the JRE.
i have use it using launch4j
follow the following steps
1-create project directory called e.g:project
2-copy the runnable jar file to it
3-copy the jre directory to it u can rename it or keep name as it e.g i will call myjre
run launch4j program :
1- fill the basic tap with required information .
2- go to JRE tap there is a field called (bundle JRE path ) write "myjre" add min Jar virsion 1,6 it will case you an error if you do not fill this fields
and then click run button to generate exe file , you have to remember to keep the myjre directory with along side with executable exe file
e.g the application directory should contains :
1- [you app name].exe
2-myjre
in this description you can run your application with no care if jre is installed in a machine or not and become portable
Good Luck , feel free to contact me for more details

JSmooth question on bundling a JRE

I'm trying to bundle a JRE with my jar file so that I can run my application on any windows computer, regardless of if it has Java or not. The jsmooth manual says:
For the option to work correctly, you have to put a JRE in a directory near the EXE (generally in a subdirectory called "jre" or whatever). Once the exe is generated, it will FIRST try to locate the JRE at the location mentioned. If it can't be found there, then it will fallback in the normal jre look-up mode (search for a jre or a jdk in the Windows registry or in commonly-used environment variables). There is no JVM-version check when using a bundled JRE, as the packager is supposed to bundle a suitable JVM for the application.
Does this mean that the jre subfolder should be included in the jar, be its own separate jar, or put in the folder that comes along with the exe? If it is supposed to be in a folder with the exe, how can I specify the relative path to the jre subfolder?
My directories are as follows:
setup/
-jre/
-myprogram.exe
I tried using ..\jre, .\jre, ..\setup\jre in the GUI screen, but none of them worked.
Any ideas or leads would be greatly appreciated. Thanks so much!
EDIT: when I tried jre (and ..\jre I think), I got the following error message from windows when I tried running it "MyProgram.exe has stopped running." When I look at the problem details, it says APPCRASH and the fault module name is jvm.dll
just put the "jre" folder next to the exe, and write "jre" (without quotes) in the GUI of jsmooth
As an alternative, I would suggest using the mature open source project, NSIS. You could write an installer that would download and install the JRE, and then create shortcuts to run your program.
Here are some useful links:
http://nsis.sourceforge.net/Simple_Java_Runtime_Download_Script
http://nsis.sourceforge.net/Java_Launcher
Have you tried Launch4J (http://launch4j.sourceforge.net/), we switched from JSmooth to this a while ago, as it was more up to date and had more features.
But, put the jre folder in the same folder as the .exe, then use jre\ as the path to it. You'll need to make sure the working folder of the .exe is the installation folder though. And make sure you have a full JRE in the jre folder.

Categories