It is a really simple thing but I cannot get my head around it. I have looked at plenty of StackOverFlow post and as well as on internet.
My goal is to create a .bat whi
Create a plain text file (using notepad) and type the exact line you would use to run your Java file with the command prompt. Then change the extension to .bat and you're done.
Double clicking on this file would run your java program.
I reccommend one file for javac, one for java so you can troubleshoot if anything is wrong.
hey I think that you just copy your compiled class files and copy the jre folder and make the following as the content of the batch file and save all together any windows machine and just double click
@echo
setpath d:\jre
d:
cd myprogfolder
java myprogram
I just made a simple batch script that takes a file name as an argument compiles and runs the java file with one command. Here is the code:
@echo off
set arg1=%1
shift
javac -cp . %arg1%.java
java %arg1%
pause
I just saved that as run-java.bat and put it in the System32 directory so I can use the script from wherever I wish.
To use the command I would do:
run-java filename
and it will compile and run the file. Just make sure to leave out the .java extension when you type the filename (you could make it work even when you type the file name but I am new to batch and don't know how to do that yet).
Am i understanding your question only? You need .bat file to compile and execute java class files?
if its a .bat file. you can just double click.
and in your .bat file, you just need to javac Main.java ((make sure your bat has the path to ur Main.java) java Main
If you want to echo compilation warnings/statements, that would need something else. But since, you want that to be automated, maybe you eventually don't need that.
I do not have a JDK installed on my machine to verify this, but here's something to get you started with
%CLASSPATH%=C:\Program Files\Java\jdk1.6\bin rem or whatever your path is
START %CLASSPATH%\javac Main.java
START %CLASSPATH%\java Main