View Full Version : Self-Installers
Floppyman
04-05-2004, 12:29 AM
Hi all,
I've written a program in JAVA that consists of many classes. I'd like to somehow create installer that installs all the files and let's you launch the program. Right now it always runs through the compiler (JBuilder) and I'd like to get away from that. TIA.
I use this one (http://nsis.sourceforge.net/), it's free, and easy to use.
And I suggest you put all of your classes in one JAR file, and include the JRE in your package or tell the user how to get it.
Floppyman
04-10-2004, 01:13 PM
Hi,
Thanks for the link. I downloaded Nsis install software. Is there a place that shows you how to use the scripting language that is involved with it? Also how would you install a JAVA program? You said put the files into a JAR file, but is there anything else I would have to do? Thanks again.
Hi Floppyman,
You don't need to know the scripting language to create an installer, just download NSIS 2.0 and HM NIS Edit, both are available in the download page (http://nsis.sourceforge.net/download/), install them both, then start the HM NIS Edit, select "Create new script using wizard", and follow the instructions, then compile the generated and script, and the installer .exe should be generated.
As for installing a Java program, create a JAR file out of the class files, configure the installer to copy this file to the installation directory, and create a shortcut for it in the start menu.
If the JRE is installed, the program will start when the user clicks on that link.
Finally, how to create a JAR file, compile your program, and copy all .class files to a new directory, inside that directory, create another directory called "META-INF", in this directory, create a text file called "MANIFEST.MF", open it in a text editor, type the following:
Manifest-Version: 1.0
Main-Class: ClassName
ClassName is the name of the class that contains the main method.
Now in the command line, cd to the directory that contains the .class files, and enter the command:
jar cMf program.jar *
And your JAR file should be there.
NSIS docs:
http://nsis.sourceforge.net/Docs/
More info on JAR files:
http://java.sun.com/docs/books/tutorial/jar/
Good luck.
Floppyman
04-10-2004, 09:39 PM
Hi,
Thanks again for your help. I tried the command to create the .jar file but it did not work. I'm working on a windows 2000 box (unfortunately:)). So, I created a .jar file through Jbuilder, however I still can not launch it. When I try to open it with javaw.exe it says the main class cannot be found. I can open it through the commandline like this though:
java -jar myprogram.jar
and it will launch right up. Any ideas? Thanks again.
Hi,
I forgot to say that you need to add two blank lines to the end of the MANIFEST.MF file.
Does it help?
Floppyman
04-11-2004, 09:36 AM
Hi,
Well when I tried the jar command from the command line it says the command was recognized (even if I try from within the JAVA folder). That's why could never create the JAR file. I was able to create one with JBuilder, but when I doubleclick on it, it doesn' t open it. What application should be used to open it? I can launch the jar file fine from the command line and it works? This is all in windows. Thanks again.
Do you have the Java SDK installed? jar.exe is in the bin directory.
Set your Parh environment variable to contain this directory:
Control Panel > System > Advanced > Environment Variables, edit the Path variable and add c:\path\to\jdk\bin to it.
Floppyman
04-11-2004, 01:08 PM
Hi,
Thanks again for the reply. Does the JDK have to be installed as well? I thought I only needed the JRE. I willl give this a try though and then try the jar command again. Thanks again.
Hi,
You only need the JDK when creating the JAR file, the JRE can run JAR files just fine, but it can't create them.
So include the JRE with your installer, not the JDK.
As for the Path variable, no the JDK doesn't change it.
Floppyman
04-11-2004, 08:33 PM
Hi,
Thanks again for the reply I think I got everything working. I ended up creating the JAR files in JBuilder. I changed some settings on my file extensions and now I can double click on the JAR files an open them. I guess you need to have type "Executable JAR File" in your file types list, otherwise it doesn't work. I couldn't do this before, but after installing the JDK it started working. Strange. I wonder if that had anything to do with it.
Is there anyway of turning a JAR into a .exe executable? Also how could I create custom icons for my program and have the install script use them? Thanks again.
Hi,
There are some compilers that compile Java into native code, but I don't think there is any complete one, the compilers I tried didn't support all of the Java library.
However, there are programs that create a .exe file out of the compiled .class files, when the .exe is executed, it starts the JRE and the main .class file.
I suggest you stick to JAR files, as long as the JRE is installed, the program will run fine, to make sure that your program runs even if javaw.exe isn't associated with .jar files, create a shortcut to "javaw.exe path\to\.jar instead of a shortcut to the .jar file itself.
As for changing the shortcut's icon, look in the created script for the command:
CreateShortCut "path" "name"
Add "" and then the icon path to its end:
CreateShortCut "path" "name" "" "path\to\icon.ico"
For more info, read CreateShortCut documentation.
HTH
Floppyman
04-12-2004, 04:24 PM
Thanks again. Is there any software that would allow you to create custom icons? TIA.
Sorry, I don't do graphic design, I think you need to ask in the General Software forum or something :D
Floppyman
04-24-2004, 08:31 PM
Hi again,
I have one more question for you. What option would I have to add into the installer script so that a certain part of the program is not checked by the default to be installed (in the installer)? Thanks again.
Hi,
Create a section for this part in the wizard, after that the script is generated, search for something like:
Section "SectionName" SEC#
And change it to:
Section /o "SectionName" SEC#
And don't forget to check "Allow user to select the components to install" in the wizard.
Good luck :)
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.