Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Could I use a batch file to run a Java program?
Is it possible to include a set of instructions into a Windows batch file so that when opened, it will execute the byte code file for a Java program? I do not know if batch files need the compiled .class file, or if they use the source code, but I need it to be able to run it as it would in its development environment (without opening the IDE though).
I have had no success with other methods of running Java files so I want to know if using a batch file is a way to do it. If so, please give a process for creating a batch file and making it work with advanced package programs such as those using TerminalIO and BreezySwing.
Here is some information about my Java system:
- IDE: JCreator
- Currently using jdk1.6.0_07
- jdk is installed in this directory: C:\Program Files\Java\jdk1.6.0_07
- PATH environment variable is set to the 'bin' folder of the jdk.
- I have both the TerminalIO and the BreezySwing add-on packages installed in the 'bin' folder of the jdk.
- All of my programs can be made, compiled, and run in JCreator successfully.
Ten points and thumbs-up awarded for the most useful and detailed answer.
4 Answers
- 1 decade agoFavorite Answer
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.
If you can't see extensions in Windows Explorer, click on Tools, Folder Options..., the View tab, uncheck "Hide extensions for known file types" and click "Apply to all folders". You will then be able to rename from .txt to .bat easily.
- 1 decade ago
ok
before you can run your program written with java by a batch file you need to know how batch file work
i will assume that you don't know
batch file is a kind of file that group a number of dos command to be execute as a program
most of dos command can be used to write a batch file and there are a number of command can be used in batch file but not in dos
------------------------------------------------------------------------
in jdk there are to executable file called java and javac
you know that javac is used to call compiler to compile your files (class) and the file java is used to call the executer to execute your file ( executable class wich contain main method )
i read that you have installed jcreator
in jcreator configuration when you used it(jcreator) to the first time the jcreator asked you to define the location of jdk
he didn't ask you that for nothing
but he asked you that to use the 2 files ( javac and java )
but to dos or batch file those to file are not registerd then if you write javac or java in dos an error occure
for that you need to register those two files to be known by cmd or batch file
to register them if you are using windows Os ( winxp sp1, sp2, or other )
first go to the location where you have installed you jdk by default it's :
C:\Program Files\Java\jdk<<<jdk version>>\bin
note it's important to include the name of the folder that contain java and javac ((called Bin))
example :
C:\Program Files\Java\jdk1.5.0\bin
copy this address
Second:
go to :
1- right click mycomputer
2- choose properties
3- choose the Advanced
4-environment variables
5- a window appear go to the System variables
6-in the scroll box choose path ( vaiable )
7- click Edit
8-at the end of variable value textbox text write semicolon (;)
9-paste the address that you have copy
10-write a semicolon (;)
you have now registerd all executable file in the bin folder and the most important two file are ( java and javac)
now you can write in dos (cmd ) java to execute file but you need to give all tha address of the location of the class
example :
java c:\prog\test
not test is class file but when you use java (command ) don't wirte the extension .class
if you want simply to write java test
you need to tell the system where the file test (class ) exesit
you can do that doing those steps :
1- right click mycomputer
2- choose properties
3- choose the Advanced
4-environment variables
5- a window appear go to the System variables
6-in the scroll box choose CLASSPATH (vaiable )
( if it doesn't existe create it by click new
in variable name write CLASSPATH
in variable value paste the address of the location of the executable class file that you want to execute for example
c:\pro;
)
7- click Edit
8-at the end of variable value textbox text write semicolon (;)
9-paste the address of the file
10-write a semicolon (;)
now you have finished all resitration of variable needed by the system
----------------------------------------------
now you can creat the batch file
go to notepad
write
java <<the name of you executable class file >>
note : again don't write the extension .class
click file save
file type write bat
save it
now you have you batch file that execute your file
with my respect
- Anonymous1 decade ago
A batch file can run any file you can run from the command line, and in exactly the same way.
- Anonymous5 years ago
Read up on how to call javac from the command line to compile your java code (See Sources). Once you can compile your code from the command line, you can create a batch file to automate the process. The batch file is basically a text file (with .bat extension) which lists each command you want executed one after another (similar to typing command after command on the command-line).