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...
> 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
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 :-)