For two days i has been search how to run a program written in java language by using Command Prompt. Below is the tutorial about how to that....
1) create a directory with src\ and tests\ in it (the tests is optional if you are not using JUnit).
2) assuming you have "package myjava;" at the top of your files (and make sure that this is what your prof wants, it becomes a pain to mark things if they are not in the right place), make a src\myjava directory (and if you are doing junit a tests\myjava directory).
3) copy your files into the src\myjava directory
4) delete your NetBeans project and recreate it as a new on with exising sources. When you are setting up the src (and optional test) directories add the src\ (and optionally the tests) directory. DO NOT add the src\myjava directory or it won't work in NetBeans.
5) make a directory called classes\ (so you you have src\ classes\, and maybe \tests all in the same place)
6) on the command line type javac -d classes -cp classes src/myjava/*.java * -d tells the compiler where to put the .class files * -cp tells the compiler where to look for classfiles * src/myjava/*.java tells it to compile all of the .java files in src/myjava
7) run it via java -cp classes myjava.Main * -cp classes tells it to look in the classes directory for the .class files * myjava.Main is the name of the class to run
Wednesday, July 22, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment