I'd like to create a single executable file for Windows with the JVM packaged inside of it.
Therefore, the user will be free of installing java and assigning the JAVA_HOME system variable.
I can't find an appropriate guide for this stuff.
I think you want to use Launch4J, which is exactly what you need.
Here is a link : http://launch4j.sourceforge.net/
It packs a jar into a exe with the JRE inside.
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.
The Java application has the JNI module to use.
Where should a user (or an installation script of this application) put the JNI module on Linux (Ubuntu) or on MacOS X so that this JNI module could be loaded without specifying the path to the module in code?
This is a link to a detailed explanation of shared objects and how they are searched for by the OS.
I wish Java people would stop using LD_LIBRARY_PATH and start using the existing directory structures and the ld.so.conf mechanism. Even the OpenJDK libraries are dumped in a place that's not on a standard path and they don't add an ld.so.conf file either ( just how hard is that ? ).
This approach avoids the need to set up your own LD_LIBRARY_PATH and launch via a shell script.
If a required shared object is to be installed, first test for somewhere like /usr/local/lib as an installation choice system wide, and if it exists and an existing file does not already use your file's name, then put your library there. A more systematic approach would be to check all the ld.so.conf files and see if any of the directories match something you know can be used. A shell script can do that at install time.
Put the compiled libraries (.so files on Linux or .dylib on MacOS) into a directory of your choice and include this directory in the library search path LD_LIBRARY_PATH used to start your JVM.
If you have a small program, you can run jar file and it will work fine. But if you convert jar file into exe, you still need java to run your exe file, so what's the difference between them and why do some people convert jar to exe?
An EXE is, ostensibly, an executable program that launches the local java to execute the bundle classes.
As you may know, on your computer you can associate certain file extensions with local programs. For example, .doc files with your word processor.
Similarly, .jar files can be associated with Java, so that Java can execute them. The jar file is considered "stand alone" if it has all of the necessary classes bundled within it, and a proper manifest pointing to the startup class.
So, by associating .jar with Java, clicking on it in your environment will launch Java with the given jar file.
An EXE doesn't need that association. It find java on its own with it's own launcher.
The next step is that you can actually bundle the JRE in to an EXE, so you don't even need to have the user install Java as a pre-requisite. But that's a different process.
People commonly use Java executable wrappers for two reasons - 1. to simply deployment for environments without a JVM, and 2. To make sure the exact Java runtime used for developing the application gets used to run the JAR. However, the practice is not that much widespread.
Java archive or jar is an archive of compiled java byte code and resources which can be run on a java virtual machine. ".exe" is a windows extension for directly executable code mostly used by installers or programs that do not need to be installed. I think your "people" are talking about installers.
An Exe file is an executable file that can be executed in Microsoft OS environment.
Jar file is container of Java Class files, including other resources related to the project. Jar file can be executed only if Java run time environment.
The JavaTM Archive (JAR) file format enables you to bundle multiple files into a single archive file.
The .class files compiled from java files, can not be launched directly. That is why it is needed to be converted to exe before it can run in a windows environment.The usual way to start a java program by batch file is not a convenient way. So inorder to avoid this difficulty we need to convert jar files into exe file.
Also converting it to exe. enables the program to run by simple double click on the program, instead of having to compile it with an IDE or through the JVM.
All that the exe will do is to start a jvm with your app, something like this: "java -jar app.jar".
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.