sorry if it feels a noobish question. My doubt is, if I converted a jar file to .exe file using software, such as exe4j or launch4j, will it still require a JRE enabled system to be able to run it, or will it just run like normal windows executable?
Also, I wanted to know if there is any other way to convert jar files to exe without using 3rd party software, also, are there any side effects of converting a jar program to exe.
Of course it needs a JRE, these tools just make it possible to run Java applications more easily on Windows. The application itself is still a Java application, it is just wrapped in a launcher.
I myself would just create a batch file to start the application (or write a few-line simple application with the single task of starting the jar).
Update: exe4j and launch4j can embed a JRE.
Related
I'm very new to java. I'm developing a tool that checks if your PC meets some set of specifications. This included writing and executing a separate batch file and including an API (SIGAR) for the model of the CPU.
My problem is that when I tried exporting it to Runnable JAR in eclipse, and I ran the resulting JAR from command line, it gave me lots of 'DLL not included in build path' Exceptions. After including the folder that contains the API DLL in the build path, I got similar exceptions. The thing that fixed it was adding the folder containing the DLL to environment variables (PATH) in Advanced System Settings.
Questions:
The JAR now works fine on my computer, but what about the users who download the JAR? Will they also need to add the DLL to environment variables? If so is there a way the JAR can do that for them?
My JAR won't run with a double-click, but will run from command line. Is there any way around this that will carry over to users who download the JAR too?
If the user downloads the tool and can't run it because they don't have the right version of the JRE, will the tool notify them? If not, is there a way around the user having to update JRE or will wrapping as an EXE suffice?
Thanks in advance, much appreciated. Lots of questions.
Q1: The JAR now works fine on my computer, but what about the users
who download the JAR? Will they also need to add the DLL to
environment variables? If so is there a way the JAR can do that for
them?
You can put a DLL inside a JAR file:
How to make a JAR file that includes DLL files? (Hint: read both answers ... completely.)
However, when you distribute a JAR containing a DLL, you then have the problem that different platforms require different DLLs (or whatever). Even with Windows you have the problem of 32 bit versus 64 bit DLLs.
Q2: My JAR won't run with a double-click, but will run from command
line. Is there any way around this that will carry over to users who
download the JAR too?
You cannot address that problem in a JAR file. The "double-click to run" functionality is implemented by the OS. The best way to provide this kind of functionality is using (platform specific) wrapper scripts that are double-clickable.
Q3: If the user downloads the tool and can't run it because they don't
have the right version of the JRE, will the tool notify them? If not,
is there a way around the user having to update JRE or will wrapping
as an EXE suffice?
Unless you have a JRE installed, the JAR file is just a passive blob of data. (A ZIP file, actually).
If the user has a JRE that is too old, then either the JRE will be unable to load any classes in the JAR (because the classfile version number is wrong), or you will get errors because of missing (system) classes.
The only hope would to do something like providing a wrapper script to launch your application that checked the JRE version before attempting to launch the JAR.
As a general rule, if you want to do fancy stuff like this you need to distribute your program in an installer, not as a bare JAR file.
I am using Excelsior JET to convert my JAR into an EXE.
I want my application to be Standalone. Literally one single file without needing installation. JET creates an EXE and also a runtime folder.
The solution, according to them, is to use 7z to create a self-extracting file (into a temporary) that will run the application.
The problem is that the self-extraction takes a long time, so program startup is ridiculous.
So my question is: is there another alternative to pack my EXE and runtime into a single standalone file?
I am using launch4j to wrap up my jars as .exe - works fine for me so far. I read about how people managed to wrap the JRE into the file using launch4j in this post:
How to bundle a JRE with Launch4j?
hope that helps - never tried myself...
DISCLAIMER: I work for Excelsior.
There were some changes made in Java 8 aimed at enabling the creation of standalone executables, such as JEP-178. It was unfeasible for us to implement this feature ourselves for earlier versions of Java. That said, we have only moved to Java 8 in Sep'15, and standalone executables are not in our near- to mid-term plans due to (relatively) low customer demand.
I finished a small program. What is the standard file type for the final application written with Java, so it can be run on any computer, easily and without any computer knowledge?
I've been told it's JAR, but Eclipse for example is an .exe file.
What's the standard file type for big, normal applications in Java?
Are most applications distributed in JAR, or rather in .exe or something else?
Serious desktop applications are packaged with platform-specific launchers, which are not written in Java. The launcher must first find out how to run the JVM installed on the system, and then pass it either the path to the executable JAR to run, or the complete classpath along with the name of the main class.
In other words, "it's complicated".
Most desktop applications are distributed using .jar files. A .exe is windows-specific, and non-portable across different operating systems. It's easy to find installers (or "launchers") that will simplify the distribution of a Java program in other platforms, but anyway you'll find that .jar files are the usual packaging mechanism.
If you have a small, simple Java program the easiest approach to distribute it would be to pack it in a .jar, making sure to make it executable. And remember, the computer where your code is expected to run must have installed some version of Java, be it JRE or JDK.
Desktop java applications are usually distributed as jar files.
JRE can launch a runnable jar file using -jar param.
You have one of several options:
1 - Create an executable jar file. By providing information in a manifest within the jar file users can simply execute the jar file by however system-dependent means exist for their OS.
2 - Write a batch file or shell script to invoke the JRE against your jar file (and specify command line parameters for, eg: the main class, the classpath, JVM options, etc.)
3 - Use a tool like jexepack or jsmooth to wrap your Java code within a native executable. I've only ever used these to create Windows binaries - there may be other options for other platforms but shell scripts are typically easier to work with here.
I have exe file called Myapp.exe. Now I want to convert .exe to jar file. That jar file should also work in NON JAVA system. I don't have any idea to implement it. Can anyone please suggest me how to do it?
Direct conversion not available !!!
because they are in entirely different platforms.
Meeting your requirements is impossible for two reasons.
1) You cannot change an EXE to a JAR file.
2) You cannot run a JAR file on a system that doesn't have Java installed.
If you want to run something on a (Windows) system with no Java installation, it needs to be an EXE ... or something else that doesn't require Java.
(It might help if you explained why you think you need to do this. Perhaps there is an alternative set of requirements that are not impossible to meet.)
why i am doing all those stubs is for making my jar has to work in java not installed system.
It needs to be an EXE then!
I have an jar.It is working fine in java installed system.My task is to Bundle jre inside jar(Not along with jar(i.e we can put jre and jar in same folder to run a jar as given in following url mindfiresolutions.com/… ))Because i have to give jar file only to client,in such a way that they can use this Myapp.jar in non java system also.But,i don't know how to bundle jre inside jar.I Don't how to run jre inside jar?
Ermm ...
Is it possible?
No. You cannot embed a JRE inside a JAR file in any way that would allow it (the JAR file) to run your Java code without first installing Java. (And installing Java would defeat the purpose of embedding the JRE ... of course.)
But what you can do is create an EXE file which has a JRE and a JAR embedded in it. And there are tools for doing this. Here's the canonical Question on how to do it:
How can I convert my Java program to an .exe file?
I think you need to read the Oracle documentation on what a JAR file really is, and how Java programs are normally executed. That will help you understand what is feasible ... and what is nonsensical.
If C# or VB.NET is distributed in .exe files as MSIL codes, what is Java distributed in? Is there an equivalent form of .exe files for Java (other than .jar files, which I don't think is good for distribution on computers). Or is there a way to save Java intermediate language(?) in an exe like MSIL does? Then distribute it in an exe which is still run by the JRE upon execution.
Java "executables" are either .class or .jar files. It's common to deliver a script (.bat file for Windows) with a Java program to run it.
You can use Launch4J to create executable *.exe files from *.jar files, but this is platform specific and using runnable *.jar files is recommended.
For more information on how to make executables with Java please take a look at this thread.
Use Java Web Start to install the app. JWS offers auto-update, splash screens and a lot of other nice functionality.
The user gets desktop shortcuts and menu items if they are requested in the launch file and supported on the OS of the user. Those shortcuts might have icons as supplied by the developer.
What 'jar', what 'exe'? Why show the user either when installing a Java rich client? Using JWS would require Jar files, but the user never sees them.