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
Related
I am working on a Java desktop application and want to execute an .exe file upon some user action.
I want to package the .exe inside the executable jar so that I have to ship just one item to my customer/user. But so far I have not been able to execute an .exe file which is packaged inside the jar.
One more input, the .exe in turn uses a bunch of .dll, .xml and .exe files (total 12 files), so I need to package all of them to make this work. Is this possible in java or should I use another language to achieve this?
I chose java because I want to support Mac platform also. So with these .exe and .dll files (for Win), I need to package and execute a bunch of Unix executable files and dylib files also (for Mac).
What would be the best way to achieve this?
I can think of 2 ways:
Make one Java executable app and dynamically execute exe or Unix executable file depending on platform it is running. The problem here is executing the files which are packaged within the jar.
Make separate applications for Win and Mac. In this case, which languages should I use?
Thanks much for the help!
Applications are packaged very differently on windows and mac. For the Windows version I would recommend you to distribute an installation program (see IzPack for instance) that will unpack the jar and the exe in the application directory (I don't believe you can directly execute an exe that's in a jar file). A MacOS application is actually a directory with a certain structure, so in your case, the said directory could contain both the jar and the exe.
I'm new at Java for Mac developement and I spent a lot of time finding a way how to create an installer. It's strange but it's not too much information about it. All the ways lead to using of JavaAppLauncher. (I use appbundler-1.0.jar and Ant to build .app) But I faced a following problem.
JavaAppLauncher sets working directory to user folder. My application consists of several jar files, resources and configuration files. All of them located in Contents/Java inside the .app structure. I use relative paths to them, relative to the executable jar with Main class.
I googled 2 discussions only, where someone asked how to set the working directory inside the .app bundle. Threre is a way to sed -Duser.dir JVM option in plist file of .app bundle. I tried this and it behaves strange. When I use "new File(".").getAbsolutePath()" - it shows the directory I pointed in -Duser.dir parameter, but when I try to create file on disk or read file from disk - it still goes to the user folder as it was by default.
May be someone knows what is wrong there?
Or is there any better way to create a java application bundle for Mac?
Thank you, guys.
Use JarSplice to create OS X app bundle. Compile all your jars and resources into one jar file and export as mac .app file.
Deploying Java Applications can be a pain if your application has multiple jars and native libraries. There are the options of using Java Web Start or Java Applets however these are not always suitable.
Executable Jars are an option, however if your project has multiple jars or native files then it can be tricky to use this option.
JarSplice attempts to solve this issue by allowing you to merge all your jars and native files into one, easy to use executable jar file.
Features:
Creates a single executable fat jar via an easy to use GUI.
Automatically extracts only the native files needed for the OS the jar is running on.
Automatically cleans up any extracted native files after the application quits.
Add VM arguments on jar creation which removes the need to enter them via the command line.
Optionally create a Shell Script (.sh) launcher for Linux with embedded fat jar.
Optionally create an OS X App Bundle (.app) for running your application.
Optionally create a Windows Application (*.exe) for running your application.
This is the best cross-platform installer creator i have found yet. You can get the java executable from here
I try to convert a jar file to an exe file.
I followed the instructions provided here using launch4j .
I get only an XML file but no exe as expected.
Any ideas?
So how should I deploy my application?
Your user would have to have the JRE installed on their computer. However, you could also distribute java.exe and rt.jar (the java run time jar) as well as any library jars you need for your application along with your program. Since the java command has an optional classpath parameter you could write a batch file (something like runme.bat) which would look something like this:
java -cp rt.jar;myapplication.jar;otherjars.jar MyMainClass
This is still Windows specific because the java.exe file would be a Windows specific file. You could also add in logic to check for the environment variable JAVA_HOME and if that's set on the user's computer then the java program specific to their OS would be in JAVA_HOME/bin
Your real problem comes when you're not sure what operating system your user will be using AND you don't know if they have Java installed. If you simply require that the user has the Java Runtime Environment installed then you're problem is solved for all users.
I hope that helps.
Greg
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
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.