compile and execute java file batch file problem
Given this .bat file :
@ECHO OFF
echo === Compiling and executing bat file ===
md C:\my_project\dir_prog\class_files
copy ProgAudioJ.java C:\my_project\dir_pro开发者_开发知识库g
javac -d C:\my_project\dir_prog\class_files ProgAudioJ.java
java -classpath C:\my_project dir_prog.class_files.ProgAudioJ
I'm wondering what's wrong with it.
It just doesn't work.
I mean it places the class files in the directory called class_files (so the compiling process is ok) but the program doesn't run...
Thanks for your help MAX
Do you have defined a main class within your project and do you have defined the
public static void main(String[] args) method for this class? Remember, that method gets called when running stuff from shell...
EDIT: you might find this comprehensive overview usefull: Running a Java Program from Command Prompt @ SkylightPublishing.com
HTH
I think the first problem is that you need to specify the class_files directory on the classpath.
The second problem is that you have to specify the fully qualified name of the class that you want to run. This depends on the package that you have defined in the Java source file.
So something like this should work: (I'm assuming your class is in the default package, i.e. no package)
java -classpath c:\my_project\dir_prog\class_files ProgAudioJ
Can you provide the contents of the source file?
If your code and command is correct, I would suspect a delay, related to the asynchronous execution of the javac or to the filesystem.
Try adding a pause command in order to check if problem is the rapidity of execution of the commands or if the problem is in the command.
精彩评论