Can we create a batch file to run Java program?

Hi,Can we create a batch file to run Java program?Regards,Kalyani
[93 byte] By [kalyani_bhadekara] at [2007-11-27 9:23:44]
# 1
Have you tried? Have you any reason to think this can't be done?
georgemca at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 2
Personally (on windows) I usually use a "shortcut" link. Create a shortcut on your desktop to the javaw program in the JRE bin directory, then edit the link to add the program to run, and set the working directory if required.
malcolmmca at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 3

I tried with

@ECHO OFF

set PATH=%PATH%;%JAVA_HOME%\bin

ECHO Compiling Java Class

javac SampleTest.java

ECHO Compiled Java Class

ECHO Running Java Class

java SampleTest

ECHO Successfully ran Java Class

And my java prog was saved on local drive.

At this time everything worked fine..

But when I created a project BatchTest in eclipse with sampleBatch.BatchTest class.

And created a batch file with following code, placed it in sampleBatch package, it's throwing error on cmd as "java.lang.NoClassDefFoundError:"

@ECHO OFF

set PATH=%PATH%;%JAVA_HOME%\bin

ECHO Compiling Java Class

javac BatchTest.java

ECHO Compiled Java Class

ECHO Running Java Class

java BatchTest

ECHO Successfully ran Java Class

Regards,

Kalyani...

kalyani_bhadekara at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 4

> I tried with

> > @ECHO OFF

> set PATH=%PATH%;%JAVA_HOME%\bin

> ECHO Compiling Java Class

> javac SampleTest.java

> ECHO Compiled Java Class

> ECHO Running Java Class

> java SampleTest

> ECHO Successfully ran Java Class

>

>

> And my java prog was saved on local drive.

> At this time everything worked fine..

>

> But when I created a project BatchTest in eclipse

> with sampleBatch.BatchTest class.

> And created a batch file with following code, placed

> it in sampleBatch package, it's throwing error on cmd

> as "java.lang.NoClassDefFoundError:"

>

> > @ECHO OFF

> set PATH=%PATH%;%JAVA_HOME%\bin

> ECHO Compiling Java Class

> javac BatchTest.java

> ECHO Compiled Java Class

> ECHO Running Java Class

> java BatchTest

> ECHO Successfully ran Java Class

>

>

> Regards,

> Kalyani...

When you say "put it in the package" I suspect you put it in the src folder, whereas the classes will be in the bin folder

georgemca at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 5
No.. i have my .class files directly in the "sampleBatch" package.
kalyani_bhadekara at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 6
> No.. i have my .class files directly in the> "sampleBatch" package.You mean in the same folder as the source files?
georgemca at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 7
yes. Both .java and .class files are present in sampleBatch package itself.
kalyani_bhadekara at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 8
Try adding the following after the set path statementset CLASSPATH=%CLASSPATH%;.;
ita6cgra at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 9
> yes. Both .java and .class files are present in> sampleBatch package itself.Doesn't actually make sense. You mean they're in the same folder? The folder != the package. Why have you got source and class files mixed up like that?
georgemca at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 10

Forgot to mention if you have a package (which you should be using and I think you are) you will need to cd into the directory to compile the files then move out of the package to run the java function. A sample is given below:

@ECHO OFF

set PATH=%PATH%;%JAVA_HOME%\bin

set CLASSPATH=%CLASSPATH%;.;

cd test

ECHO Compiling Java Classes

javac *.java

ECHO Compiled Java Class

ECHO Running Java Class

cd ..

java test.RunMe

ECHO Successfully ran Java Class

cmd

test is the name of my package cd .. goes back up a level after compilation and RunMe is my main class. There is probably an easier way but I don't normally use a bat to compile/run java files :-)

ita6cgra at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 11
Thanks a lot..It's working fine now..
kalyani_bhadekara at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...
# 12
No problemo dude... God I miss the original TMNT :-(
ita6cgra at 2007-7-12 22:19:09 > top of Java-index,Java Essentials,Java Programming...