I've created a JavaSE app in Netbeans and am using Inno Setup 5 to generate what I thought was a complete Windows installation, including JRE. As instructed, I have checked the NetBeans property boxbox for Native, and have Inno Setup 5 in the Path. The EXE is generated and installs nicely PROVIDED the target machine has Java installed. If it doesn't, there's no file association with .jre and no javac.exe so the .jar file won't run.
3/4/2017: After lots of poking around and trying things today I now understand more fully what NetBeans Native packaging is really doing. It creates an Installer exe that, when transferred to and executed on a target machine with or without JRE, creates the actual myApp.exe and puts it on the Start menu. My problem has been thinking the myApp.jar file had the JRE in it, so I was just trying to double-click the myApp.jar. If I use the myApp.exe it works.
However, I now see I still have a problem. myApp requires a number of supporting data files and reading from an .ini file. Consequently, I'm going to have to create an Inno setup to do that stuff separately, and my users will have to download and run TWO installers, so to speak. Had the person who did the NetBeans Native installer thing made the Inno setup file accessible for editing, that would be neat.
Ed
NetBeans has a Packaging option for creating a "Native" application, i.e., a MyApp.exe file for Windows. The importance of this is you get a Windows executable the INCLUDES JRE, meaning that the ultimate user doesn't need to install Java or JRE on his/her machine to run the application.
This sounds wonderful, but the documentation is not at all clear about how to make it work, at least not to me. Here's what I've learned.
First, for this to work you have to have Inno Setup 5 or higher installed on you development computer. Apparently, NetBeans creates an Inno .iss file and runs it.
To understand it better I made a NetBeans projects for the Inno AnagramGame example. To enable the Native packaging option, first select the Project in NetBeans , right-click and select Properties|Deployment. Check the Native packaging box. This causes the EXE option to be placed on the NetBeans Packaging menu. I.e., Select the Project, right-click and click on Package As. Clicking EXE Installer launches the process of building the "package."
Building the installer takes a LONG time because it has to accumulate all the necessary pieces of the JRE and incorporate into the package. This also makes the installer BIG. Even for the smallest Java program it will be about 35 Mb.
After the Native packaging of some app, for example AnagramGame2, you will find the following in the NetBeans project folder:
C:\Users\Ed Sowell\Documents\NetBeansProjects\AnagramGame2\dist\anagrams.jar
and
C:\Users\Ed Sowell\Documents\NetBeansProjects\AnagramGame2\dist\bundles\AnagramGame2-1.0.exe
Anagrams.jar is the Java archive file for the AnagramGame2 app. IF YOU HAVE JAVA INSTALLED, this will actually run the project by double clicking. However, if you move it to another computer WITHOUT Java or JRE installed, it will not be executable. The reason is the jar file does NOT incorporate the JRE. It took me long time to recognize this.
Now, you might be thinking AnagramGame2-1.0.exe is the Native executable for the app but, nay, it is not. It is in fact the installer, another thing that took me a long time to recognize.
So, where is the fabled Windows Native app file? The answer is it is nowhere, yet. In order to get it YOU MUST RUN THE INSTALLER! After running it you will find the much wanted EXE in, of all places, C:\Users\Ed Sowell\AppData\Local\AnagramGame2:
C:\Users\Ed Sowell\AppData\Local\AnagramGame2\AnagramGame2.exe
Also, with the appropriate options selected, the app name will appear on the Windows Start menu and desktop.
So, to distribute the Windows Native application you have to:
Create a NetBeans project.
Do a Clean build of the project
To enable the Native packaging option for the project
Do a Package as|Native installer
Distribute the installer, in this example it is AnagramGame2-1.0.exe
Your user then runs the installer. Afterwards, he/she runs the app from the Start menu or double clicking the desktop icon.
There's still a lot I don't understand about the proper use of this NetBeans/Inno Setup process. There are some small mysteries, such as why it hides the location of the end product in User AppData Local. Who would have thought to look there? And why does it call the Installer AnagramGame2-1.0.exe instead of something like setupAnagramGame2.exe? But here's the biggest problem I've yet to solve: How does one install ancillary files needed by the app? Or get needed data out of an INI file? If the .iss that is built and used in the NetBeans process were made available it could be edited, but so far I've not been able to find it. My guess is it gets deleted. Short of that, the only thing I can think of is to write another .iss file to do that work. Unfortunately than means the user has to download and run two installers!
The problem with the NetBeans packaging mechanism using Inno Setup is that - AFAIK - you can't give your own .iss file to the build mechanism. NetBeans creates an own installation script file with little to no external influence.
The biggest problem I too have is that the package is installed (at least for Windows) in C:\Users\<user>\AppData\Local. Who on earth is going to look over there in the first place to find back an application??? Don't know why they've taken that decision.
Whenever you click the executable generated by NetBeans, you don't have any control whatsoever over location, shortcuts,... And that's too bad...
To overcome this, I did the following:
Allow NetBeans to do its job and create an executable installer
Once the installer is created, run the installer and let it install the app in the weirdest of all places on a Windows installation
Open Inno Setup Compiler and create your own installation script, using all the files and subdirectories that were created by the original NetBeans generated installation executable.
Generate my own installation executable using the above
Run the self-created installer: you now have all the options you want since you yourself created the installation executable (option to change installation directory, default installation directory, default installation directory name, use desktop shortcut or not, allow for all users or current user only, ...)
I know this is a workaround and a 2-way process but that was at the time I needed it the only(?) / best(?) way I could find.
In the mean time, I found an alternative way to create an installer executable on this page where you can create your own .iss file and as such, have much more control over what is going to happen.
I didn't try it out myself yet, but I think it has quite some opportunities.
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 created a tic-tac-toe game in Java. It runs fine on Eclipse.
How do I compile this file (which is currently a .java file) to the standard file format of Java applications, so it can be run from the desktop like a normal program?
What is the standard file type for the final executable Java application? What should be the file type if I want people to easily and without any computer knowledge run my program on their computers?
with eclipse right click on your project. then export it as a runnable .jar file.
Project Right Click > Export > Runnable .jar File.
First choose your project under "Launch configuration", then choose your destination.
After that click finish. Your program should be in your destination folder. Double click to start (just like an .exe file)
For example: If you export it to your desktop, and you name it "TicTacToe", the file on your desktop is "TicTacToe.jar" - ".jar" is your executable file
Done
You have to compile your java class first
javac TicTac.java
and then execute it
java TicTac
Note: that here you provide the name of the class with the main method!
As the other answers indicated, you can create an executable jar using eclipse (or a number of other tools). What these tools are doing under the hood is defining the Main-Class: attribute in the jar's manifest.
In Windows, your users can double click on an executable .jar to launch it, as long as the file associations are configured correctly. However this may not be obvious to windows users who are trained to expect some sort of .exe extension.
To solve this, you could use launch4j to wrap your executable jar in a windows executable. Note: this doesn't change your java application into a native application (it still requires the JVM, etc), it simply makes it launch more like a native application.
For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start. JWS works on Windows, OS X & *nix.
Note that JWS is more effort for us to deploy (it involves not only Jarring and signing the code, but creating a JNLP launch file and a page on the net or network to check that Java is installed & serve the files to the user), but is super easy for the end user.
If there is a JWS deployment, the Jar does not have to be an 'executable Jar' as described in the other answers.
The command should be javac yourFile.java from you command prompt and then after compilation, class file is created. You can run it using java MailClassName
You can find a good tutorial on using javac and java commands here.
This is my first brush with actually distributing a Java application. I'm coming from a Python background, which has a fantastic set of tools for distribution called PyInstaller, and Py2App. Both of these package up a copy of the Python Interpreter along with the application so that there's nothing to install for the end user. They simple see an .EXE or .app double click it, and the program starts.
So far, I have been unable to find a similar tool for Java. The idea behind this app is that it's stored on a flashdrive so it can be run without installing anything on the host machine.
I've found decent tools for Windows. For instance, Launch4J appears to do the trick, but it's for windows only. I'm desperately in need of similar functionality, but for making an app.
Has anyone faced this conundrum before? Are there any tools which I could use?
Have a look at install4j, it's a multi-platform Java installer (and launcher) builder. You can bundle a JRE with your installers.
Disclaimer: My company develops install4j
Lets assume you are distributing via a .zip file
You could drop a copy of the JRE in your app directory, then create a .bat and .sh script that will run the app with a java command using the JRE that is in the same directory.
There is probably a better tool to do this but this is one way it could be achieved.
A super simplified example .sh script
#!/bin/bash
jre/bin/java myapp.jar
Would run myapp.jar using the JRE in that location. In reality you would want to put checks to make sure the JRE exists.
the app folder:
myapp/
jre/
start.sh
start.bat
myapp.jar
the jre would be an actual JRE instance.
I know this question has been asked many a times and all the time there is an answer which says about using an executable jar or making an .exe using launch4j or similar app.
I may sound like a novice, which I actually am.
I have been trying a few things with a Java project. I have successfully made an executable jar and also an .exe file from it. All thanks to your previous answers in SO :)
But, I want to create a installer for Windows. Like, pressing Next for 2 - 3 times(which shows all the terms and conditions etc), then a user specify a location(like C:\Program Files\New Folder\My App), then my .exe, lib folder, img folder, other important folders get pasted in the destination folder along with the .exe file and then a shortcut is created on a desktop.
Any pointers to how can I achieve this ?
I have been using InnoSetup for a long time. It has always worked very well. It can do everything you need (unpack files, put shortcuts on desktop, start menu etc) and generates installers that we are used to.
If you want free and open source, you could take a look IzPack. We use this at work for its command line support in our builder.
You could also take a look install4j which is a commercial product we've trialed on and off before (but when it comes to spending money, you tend to want to know you're getting what you want ;))
If you are on JDK 13 or above, you can package any Java program along with its runtime by using the default packaging tool in the JDK called jpackage.
jpackage can create installers for Linux, Mac and Windows operating system.
You can create a specific runtime by using jlink.
jpackage needs some 3rd party free software for creating Windows bundles:
* To create .exe bundle, it uses Wix
* To create .msi bundle, it uses Inno
Wix is now the only dependency to create both exe and msi bundles.
All the details about jpackage can be found at JEP 343: Packaging Tool.
Edit: I'll leave this here for reference, but note: The Java plug-in needed to launch JWS and applets was removed by browser manufacturers, and both were deprecated in Java 9 and removed from the API.
Use Java Web Start.
Like, pressing Next for 2 - 3 times (which shows all the terms and conditions etc)
The ExtensionInstallerService of the JNLP API provides this. Here is a demo. of the installer service.
..then a user specify a location(like C:\Program Files\New Folder\My App), ..
The ExtensionInstallerService provides a method getInstallPath() which..
Returns the directory where the installer is recommended to install the extension in. It is not required that the installer install in this directory, this is merely a suggested path.
That is not quite the same as what you are asking, but then I think it is generally a bad idea to allow the user that level of control.
then my .exe, lib folder, img folder, other important folders get pasted in the destination folder along with the .exe file ..
JWS installs the resources mentioned in the JNLP automatically, as and when they are needed. Further, it updates the resources if the archives on the server change.
and then a shortcut is created on a desktop.
JWS can supply desktop shortcuts and menu items on supported systems.
E.G.
From How to run Java programs by clicking on their icon on Windows?
This answer, which shows a JWS app. installed in 'Programs and Features', with the desktop icon to the left of it.
I was in the same situation a few months ago. After trying out a lot. I suggest NSIS. There is a nice plug-in for Eclipse EclipseNSIS with some templates. It helps a lot to get a basic installer with just some easy clicks. If the resulting code is not sufficient you can do the rest work by coding, but most of the code is generated by EclipseNSIS.
You can also use Advanced Installer. Since you already have an EXE to launch your JAR, you don't need to use the Java Launcher support from Advanced Installer, you can create a Simple project, which is available in the free edition, so you don't need to purchase a license.
It will take you maximum 10 minutes to install it and create the setup package, as you will see it is very easy to learn using it.
use Launch4j to create exe file. you must give the relative path to jre folder.
next use Inno Setup to make setup. You can bundle jre inside the installer.
I've use it and it works like a magic. I can show details.
I wanted to share another project. This project have two part:updating your desktop app and ready installers for mac os, linux, windows. If you want only installer so you can adopt for your needs documentation in this way you should replace starter-core-1.0.jar with your jar
I have written a small java application for one of my homework. the problem is the teacher may not have JRE installed. what i want to id to compile the java file to window exe file so the teacher can run it without the JRE installed.
i use the gcj tool in the cygwin , but the output application seem to need the cygwin1.dll to run. how can i avoid this, IE package all the things the application need to a single file, so the teacher don't have to install anything.
Use MinGW instead of Cygwin.
And get ready for a 10-MiB executable.
Why don't you just ask your teacher to install a JRE, or if they have one? If you are allowed to use Java, then I'm certain the teacher will be required to have the tools for properly evaluating your homework.
If you weren't allowed to use Java, well then, what were were you thinking?
The application seem to need the cygwin1.dll to run.
Shipping an .exe with an cluster of .dll files is the norm on Windows.
If you use Microsoft Visual Studio, your program will also need be shipped with some libraries from the Visual Studio Redistributable Run-Time. (Unless you link it statically.) Most major applications on Windows have installation directories chock full of dll files, and won't run without them.
In the middle of 2016, the Cygwin project changed the licensing from GPL to LGPL. This means you can link programs with to cygwin1.dll and redistribute them, even if those programs have a license that is not compatible with the regular GPL, such as closed-source, non-freely-redistributable, proprietary programs. (If you otherwise comply with the LGPL in regard to how you are redistributing cygwin1.dll itself, of course).
IE package all the things the application need to a single file, so the teacher don't have to install anything.
The only way not to install anything is not to have a file at all. If there is a single file it has to be put somewhere, and that meets the definition of installation. On Windows, if you have a .exe file that depends on a .dll, all you have to ensure is that they are put into the same directory. This requirement can be met as easily as by putting them into a .zip file, if the program is too unimportant to warrant developing a full blown installer.
Your teacher unzips your .zip file on their Desktop, or in their Downloads directory. A folder should appear, and in that folder is your program and the dll. The program can be invoked and loads the dll; no brainer.