解析参数的工具类/**
* 从stdin 中读取配置参数
* example:
* echo "--jasypt.encryptor.password=xxx --server.port=8081" | java -jar xxx.jar
* java -jar xxx.jar <<< "--jasypt.encryptor.password=xxx --server.port=8081"
* 多个参数以空格分割.
* @author xielongwang
* @create 2018-07-16 下午5:34
* @description 从stdin 中读取配置参数,为了隐蔽ps or jps 能看到启动参数
@Slf4j
public class StdInParam {
* 从stdin 中读取配置参数
* @param args 原来的启动参数
* @return 合并后的参数
public static String[] getParamFormStdinLine(String[] args) {
StringBuilder paramBuild = new StringBuilder();
try (BufferedReader in = new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in)))) {
if (in.ready()) {
String param;
while ((param = in.readLine()) != null && param.length() != 0) {
paramBuild.append(param);
} catch (Exception e) {
log.error("reade stdin param error ", e);
//如果stdin 为空默认返回args
if (StringUtils.isEmpty(paramBuild.toString())) {
log.warn("stdin param is null! ");
return args;
//转换成启动参数
String[] stdinParam = paramBuild.toString().split("\\s+");
return ObjectArrays.concat(stdinParam, args, String.class);
public static void main(String[] args) {
String[] startParam = StdInParam.getParamFormStdinLine(args);
SpringApplication.run(xxx.class, startParam);