One of my friend told me that he used a batch program to install a java program on the machine,that placed the necessary files in a particular directory and also planted a shortcut on the desktop. How can it be done ? If there are tutorials that teach this please link me to them

- 168,117
- 40
- 217
- 433

- 22,386
- 64
- 200
- 328
-
2A batch file can run commands and commands can move files around. What platform do you want to install on? – Devin M Jan 21 '12 at 16:09
-
Why to write it on our own, why don't [just reuse](http://stackoverflow.com/questions/979572/how-to-make-installer-of-java-desktop-application-for-multi-platform) – jmj Jan 21 '12 at 16:14
4 Answers
This code is a simple batch script. Customize this code.
Code:
@echo off
color f0
:: overwrite your program name after the '=' ::
set ProgramNameHere=ProgramNameHere
goto start
:start
cd/
cd users
cd %username%
cd desktop
md %ProgramNameHere%
:: overwrite your file path on the 'DATA' ::
:: overwrite your file name on the 'file1', 'file2'...
:: overwritw your file name after the 'extracting'.
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file1.txt
echo extracting file 1
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file2.txt
echo extracting file 2
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file3.txt
echo extracting file 3
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file4.txt
echo extracting file 4
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file5.txt
echo extracting file 5
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file6.txt
echo extracting file 6
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file7.txt
echo extracting file 7
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file8.txt
echo extracting file 8
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file9.txt
echo extracting file 9
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file10.txt
echo extracting file 10
ping localhost>nul
goto exit
:exit
exit
All you need to do is use some basic windows commands to make this work. I'm not going to write the script for you but I can point you in the right direction. A batch script on windows is a simple text file ending with the .bat
extension.
You can use any command typically available on the windows command prompt (AKA cmd.exe
). A good starting point is learning how to move and copy files around so you want to take a look at the commands by the same name on the Command-line reference from Microsoft. There is also a handy guide linked on the same page to batch files and how they work.
The documentation linked is for Widows XP and the syntax of the commands should be back and forwards compatible with other Windows versions.

- 9,636
- 2
- 33
- 46
Installing a Java program is the same thing as installing a ... program ;-) You can create a batch installer from scratch with a .bat file or use an installer builder tool. I use NSIS because it's free and simple to use ... but there's others.
You also may want to build an .exe instead of a jar file (sometime, windows open the jar archives instead of launching java). I use Launch4J to wrap my java application in a .exe file.

- 1,242
- 3
- 16
- 24
If the app. has a GUI, install/launch it using Java Web Start. It works on Windows, OS X & *nix, and can install both desktop shortcuts and menu items to launch the app. on platforms that support such things.
JWS is supported & supplied by Oracle.

- 1
- 1

- 168,117
- 40
- 217
- 433