Java命令参数 -D -classpath

来源:互联网 发布:qq刷圈圈软件 编辑:程序博客网 时间:2024/06/05 04:47

比如下面的命令:

java -Dfile.encoding=UTF-8 -classpath /lib/* com.zhclab.web.Launcher file:/configuration/application-config.xml


-Dname=value

可以通过System.getProperty("file.encoding")得到UTF-8

而System的property是指Java虚拟机的参数。


其中有一些standard的属性:

KeyMeaning"file.separator"Character that separates components of a file path. This is "/" on UNIX and "\" on Windows."java.class.path"Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property."java.home"Installation directory for Java Runtime Environment (JRE)"java.vendor"JRE vendor name"java.vendor.url"JRE vender URL"java.version"JRE version number"line.separator"Sequence used by operating system to separate lines in text files"os.arch"Operating system architecture"os.name"Operating system name"os.version"Operating system version"path.separator"Path separator character used in java.class.path"user.dir"User working directory"user.home"User home directory"user.name"User account name

-classpath

(1).何时需要使用-classpath:当你要编译或执行的类引用了其它的类,但被引用类的.class文件不在当前目录下时,就需要通过-classpath来引入类
(2).何时需要指定路径:当你要编译的类所在的目录和你执行javac命令的目录不是同一个目录时,就需要指定源文件的路径(CLASSPATH是用来指定.class路径的,不是用来指定.java文件的路径的) 

-cp 是classpath的缩写,也是用来设置搜索class文件的路径。


最后的file:/configuration/application-config.xml是程序的命令行参数,在com.zhclab.web.Launcher类的main函数中可以用args[0]得到。


java启动时还可以使用-Xss256K, -Xms768m, -Xdebug等参数配置JVM的属性。-X开头的是非标准的选项,各个虚拟机厂商可以拥有自己独有的选项。

原文:http://blog.csdn.net/hongchangfirst/article/details/46637173

作者:hongchangfirst

hongchangfirst的主页:http://blog.csdn.net/hongchangfirst



0 0
原创粉丝点击