I started to learn java and I needed a fast way to compile and execute small java programs that I wrote on notepad or my favorite Notepad++ and command prompt is considered a very fast way if you know that you Don't have to rewrite the command each time you want to compile or run a java file , you can just write them in a .bat file and execute all this commands with a double click.
All what you have to do is to write the commands in a text file and save it with .bat file extension.
An example of .bat file that compiles and execute a java file in my desktop :
@echo off
rem delete the old class file to avoid executing it
rem if there was an error in the new java file
cd C:\Documents and Settings\Ahmed Kotb\Desktop\
if exist a.class del a.class
rem Compile the java file(s)
cd C:\Program Files\Java\jdk1.6.0_04\bin\
javac "C:\Documents and Settings\Ahmed Kotb\Desktop\a.java"
rem Execute
cd C:\Documents and Settings\Ahmed Kotb\Desktop\
if exist a.class java a
pause
Hope this was useful.
No comments:
Post a Comment