Friday, November 14, 2008

How to run java codes efficiently

When you run a java code under the condition of command line, you can make the long command as a bat file. Thus you need not type it again and again. Remember the format to run the compiled java code is : > java -classpath [lib jars] [your main *.class ].
After the bat file is created, locate it in the bin folder and just type run run.bat in the command line under the bin folder.

For example, here I create a bat file for the running of TestPathwayReader.java (.class):

java -classpath .;D:\jLibrary\jaxb-2_1_8\jaxb-ri\lib\jaxb-api.jar;D:\jLibrary\jaxb-2_1_8\jaxb-ri\lib\jaxb-impl.jar;D:\jLibrary\jaxb-2_1_8\jaxb-ri\lib\jaxb-xjc.jar;D:\jLibrary\jaxb-2_1_8\jaxb-ri\lib\jsr173_1.0_api.jar org.tingting.bn.mn.phylotree.test.TestPathwayReader

Please note the ".;" before the long paths of other libraries. ".;" stands for the current directory which should be included when the system is searching for the library. In windows, use ";" for path separator; In unix, use " : " as a path separator.

No comments: