How to create a .bat file

Hi,

I want to transfer and run my program on a computer

that don't have JDK. I want to create a .bat file or

something like that. How exactly is this done? I guess

I have to include all the javaclass files that my program

is using. Can I put everything in one directory and than

zip it and create the path in a .bat file?

Please help me I can't figure this one out...

[425 byte] By [MattTheSwede] at [2007-9-26 1:15:39]
# 1

You can't run a java program on a computer that don't have JDK (JRE in fact) !

Then, there are several way to put a JRE on the computer: the best is to install one but you can also put one in you program distribution package...

For more information, see

http://java.sun.com/j2se/1.3/jre/README,Redistribution of the Java 2 Runtime Environment

Floweb

floweb at 2007-6-29 0:42:22 > top of Java-index,Archived Forums,Java Programming...
# 2

Steps of creating a DOS batch file.

1. The machine that will run these Java programs needs the JRE or JDK installed on it. If it is an applet, a web browser is OK.

If you are using just standard core Java packages such as

java.awt.*

java.awt.event.*

java.io.*

java.net.*

(and others... not extension packages such as javax.swing.*, Java 3D, etc)

you may not need JDK and can just use Microsft's JVM which is jview.exe on the windows directory, C:\Windows

2. Create a new directory to store all the Java class files, data files, images and other resources that the program makes use of.

3. Create a batch file that will install and/or run the program IN THE SAME DIRECTORY as the class files.

4. Go into the batch file properties by right mouse clicking on the batch file and selecting properties. Go to the programs tab at the top and look at the 'working' and 'cmd line' properties. These two need to be blank. If there are any values in there, then delete them.

5. Zip the directory using WinZip and then create a self-extracting executable. (Just right mouse click on the directory and select the 'Add to zip' option).

6. Save to a floppy or another location.

Here is a sample batch file:

(Assumes that the directory with all your files is called myprog and is saved on the floppy disk

Your program that has main method is called Main)

rem --start batch file--

@echo off

cd c:\

mkdir myprogs

cd myprogs

copy a:\myprogs\*.* .

echo all done!

echo running application...

java Main (or jview Main)

rem --end of batch file--

If you are using UNIX/Linux then a shell script needs to be created. This is then executed by using the commands:

sh <myshellscriptname>.sh

Hope this helps!

Rizwan

r-javaid at 2007-6-29 0:42:22 > top of Java-index,Archived Forums,Java Programming...