Cyril Dex said:
Hey guys
Does anyone know of where I can get information on how to get a batch
file to change directory into where class files are located and then
rum those java files - by double clicking on it.
e.g. set $PATH="c:/j2sdk1.4.2/bin" //where the java compiler is
located
cd c:/MyProgram
javac MyProgram.java
java MyProgram
Hope this post will be useful for someone in search of this:
Batch Files.
1st Batch File:"RunJava.bat"
@echo off
cd /d %~dp0
call "D:\JavaPrograms\source\source.bat"
Pause
echo "Program Executed"
2nd Batch File:"sourece.bat"
@echo off
cd /d %~dp0
ECHO.
echo ************************************************** ************
dir D:\JavaPrograms\source\*.java
ECHO.
echo ************************************************** ************
ECHO.
set /p Name=Enter one Java file name from above list for execution:
javac -d ..\Classes %Name%.java
call D:\JavaPrograms\classes\Classes.bat %1 %Name%
echo "Successfully Executed"
3rd Batch File:"Classes.bat"
@echo off
cd /d %~dp0
echo Name=%Name%
echo Output of the Program
echo ---------------------
java %Name%
call "C:\Documents and Settings\Administrator\Desktop\RunJava.bat"
Working Help
In My system:
1. The RunJava.bat is place in the desktop. I write java programs in notepad or Editplus and save programs in "D:\JavaPrograms\source"
2. The "source.bat" is placed in "D:\JavaPrograms\source".
3.The compiled classes file are stored in "D:\JavaPrograms\Classes".
4.This is done with the help of "javac -d ..\Classes %Name%.java" <- compile and store the class file in ..\Classes folder
5.The "source.bat" calls "Classes.bat"
6.The "Classes.bat" in placed in"D:\JavaPrograms\Classes."
7.The "Classes.bat" runs the java program.
Batch File: RunJava.bat
1.Place this file any where in your computer.
2.This batch file is executed in the current directory through
cd /d %~dp0
call "D:\JavaPrograms\source\source.bat"
This is the place where the java source files are stored also this is the place for source.bat.
Batch File: source.bat
1.This batch file compiles the .java file.
2.dir D:\JavaPrograms\source\*.java: lists all the java programs in the source folder
3.set /p Name=Enter one Java file name from above list for execution:
The above statement accepts the program name like "HelloWorld" without .java extension
which needs to be compiled. Do not specify the name of the program as "HelloWorld.java".
4.javac -d ..\Classes %Name%.java: Compiles the "HelloWorld" java file and places the compiled class file under the Classes folder.
5.call D:\JavaPrograms\classes\Classes.bat %1 %Name% : Calls the Classes.bat file which is residing in Classes folder.
Batch File: Classes.bat
1.Classes.bat resides inside Classes folder.
2.This batch file runs the java program "java %Name%";
3.call "C:\Documents and Settings\Administrator\Desktop\RunJava.bat": Call the RunJava.bat file.