【发布时间】:2022-02-15 17:16:49
【问题描述】:
我希望我的程序在运行启动脚本时会这样运行:
/opt/bin/java -Dgroup.profile=GROUP_270731 -Dother=other xxx.xxx.MainClass
而我的脚本就像
#!/bin/shell
JAVA_OPTS=getOpts
${JAVA_HOME}/bin/java $JAVA_OPTS $OTHER_ARGS xxx.xxx.MainClass
getOpts(){
# get java opts from certain file java_opts
}
我可以更改的只是 java opts 文件,我必须在其中获取某个文件中的组信息,我在我的 java opts 中这样做了:
-Dgroup.profile=$(cat /home/admin/conf/deploy.conf | sed 's|[[:blank:]]||g' | grep group.profile= | cut -d= -f2)) -Dother.args
但是,我得到了这样的错误日志:
cannot find or load main class .home.admin.conf.deploy.conf
似乎在我的 java_opts cmd 中运行了一些东西。
【问题讨论】:
-
$()内的命令的确切输出是什么? -
像 GROUP_004134213 这样的字符串
-
你的#!线是废话。
#!/bin/shell.... 这应该是什么外壳?至少我不知道任何名为 shell 的 shell。实际上,对于您的问题,我强烈建议您使用可以执行数组的 shell(例如 zsh),因为通常的解决方案是将 Java 选项存储到数组中并在调用 java 时扩展数组。 -
使用
echo打印整个命令行,或者如果你的shell支持它set -x -
我们不知道您的
deploy.conf的内容或这些转换应该做什么。它提出了一个问题,为什么您不以实际需要的格式保存文件,而不是在每次调用时转换不合适的文件。作为旁注,您可以首先使用sed op file | …而不是cat file | sed op | …。通常,如果命令本身没有输入文件选项,您几乎总是可以使用command <file而不是cat file | command。
标签: java shell command-line-arguments jvm-arguments