java -D VM启动参数含义
2022/3/20 12:27:36
本文主要是介绍java -D VM启动参数含义,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
[TOC]
-D<name>=<value> : set a system property 设置系统属性。
官方解释:
Set a system property value. If value is a string that contains spaces, you must enclose the string in double quotes 设置一个系统属性值,如果值是字符串包含了空格,则必须添加双引号
1.java -D参数简化加入多个jar
java命令引入jar时可以-cp参数,但时-cp不能用通配符(多个jar时什么烦要一个个写,不能*.jar),面通常的jar都在同一目录,且多于1个。)-Djava.ext.dirs 就可以解决 多个jar的问题
如:
# 运行MyClass的主函数时,添加java.ext.dirs属性的值为lib,即将lib中的jar包加入到这个即将启动的java进程中 java -Djava.ext.dirs=lib MyClass
2.可以在运行前配置一些属性,比如其他属性
java -Dconf1="wqbin" Myclass
可以通过System.getProperty("conf1");获得这个值
也可以从idea上看:
3.补充Standard System Properties
Key | Meaning |
---|---|
"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 |
4.测试
设置虚拟机启动参数
测试代码
public class AppRun { public static void main(String[] args) { System.out.println("----------------------------------------------------------------"); String test = System.getProperty("test"); System.out.println("VMoptions -Dtest=" + test); System.out.println("Program arguments(程序入口主函数main(String[] args)接收到的参数值)"); for (String arg : args) { System.out.println(arg); } } }
IDEA控制台输出
这篇关于java -D VM启动参数含义的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?