简体   繁体   English

命令行选项可在Windows中使用,但不适用于Linux

[英]Command-line options working in windows, but not Linux

I have a .bat file on Windows/shell script on Linux that starts a large Java application from the command line. 我在Linux的Windows / shell脚本上有一个.bat文件,可从命令行启动大型Java应用程序。 It configures the classpath, environment variables, etc. 它配置类路径,环境变量等。

At one point, it uses RMID to configure a bunch of services which will run in their own JVMs. 有时 ,它使用RMID配置一堆将在自己的JVM中运行的服务。 The problem is that it won't allow me to specify multiple JARs for the codebase property on Linux. 问题是它不允许我在Linux上为codebase属性指定多个JAR。 It's allowing me to do so on Windows just fine, but I think my syntax/styling must be wrong for the .sh script and am hoping a more experienced Linux user could have some tip. 它可以让我在Windows上正常运行,但我认为.sh脚本的语法/样式一定是错误的,并希望经验丰富的Linux用户可以提供一些建议。 On Windows, the working line looks like this: 在Windows上,工作线如下所示:

SET RMID_OPTIONS=%RMID_VM% 
    -J-DINSTALL_DIR=%CONFIG_PATH% 
    -C-DINSTALL_DIR=%CONFIG_PATH% 
    -J-DINSTALL_DIR_LOCAL=%HOME_DIR% 
    -C-DINSTALL_DIR_LOCAL=%HOME_DIR% 
    -J-Djava.security.policy=%PL_HOME%\windows\system.policy

    -C-Djava.rmi.server.codebase=
        "file:/%HOME_DIR%\jar1.jar file:/%HOME_DIR%\jar2.jar"

    -J-Djava.rmi.server.codebase=
        "file:/%HOME_DIR%\jar1.jar file:/%HOME_DIR%\jar2.jar"
     // more stuff here

The only important lines are the ones setting the rmi.server.codebase property. 唯一重要的行是设置rmi.server.codebase属性的行。 The above works 100% fine, however, when trying to set multiple JARs in the codebase in Linux, it causes a general failure and the whole RMID command is not executed. 上面的方法可以100%很好地工作,但是,当尝试在Linux中的代码库中设置多个JAR时,它会导致一般故障,并且不会执行整个RMID命令。 My shell script looks like the following: 我的shell脚本如下所示:

export RMID_OPTIONS="${RMID_VM} 
    -J-DINSTALL_DIR=${CONFIG_PATH} 
    -C-DINSTALL_DIR=${CONFIG_PATH} 
    -J-DINSTALL_DIR_LOCAL=${HOME_DIR} 
    -C-DINSTALL_DIR_LOCAL=${HOME_DIR} 
    -J-Djava.security.policy=${PL_HOME}/linux/system.policy 
    -C-Djava.rmi.server.codebase=
        ""file:/${HOME_DIR}/jar1.jar file:/${PL_HOME_LOCAL}/jar2.jar"" 
    -J-Djava.rmi.server.codebase=
        ""file:/${HOME_DIR}/jar1.jar file:/${PL_HOME_LOCAL}/jar2.jar"" 
     // more stuff here
     "

The shell script itself works perfectly fine if only one JAR is specified, but any more and I get a general failure. 如果仅指定了一个JAR,则shell脚本本身可以很好地工作,但是如果再指定一个JAR,则会出现一般故障。 Any suggestions on what I'm doing wrong? 关于我在做什么错的任何建议吗? I'm open to try new things to fix this as all my attempts so far have been fruitless. 我愿意尝试新的方法来解决此问题,因为到目前为止我的所有尝试都没有结果。

Under Linux, escaping quotes is done differently. 在Linux下,转义引号的处理方式有所不同。 You are attempting to use the Windows specific syntax, which will result in the jar files being passed as separate arguments, instead of a single one, as it should be. 您正在尝试使用Windows特定的语法,这将导致jar文件作为单独的参数传递,而不是应该传递的单个参数。

Instead of "" to produce a quote inside quotes, you have to use \\" in Linux: 相反的""生产引号之内的报价,你必须使用\\"在Linux中:

export RMID_OPTIONS="... -C-Djava.rmi.server.codebase=\"file:/${HOME_DIR}/jar1.jar file:/${PL_HOME_LOCAL}/jar2.jar\" ..."

Aside from that, I'm not sure that the file:/ syntax is correct. 除此之外,我不确定file:/语法是否正确。 It's probably either file:// or the absolute file path without anything preceding it, but you'll have to try it out. 它可能是file://或绝对文件路径,前面没有任何内容,但是您必须尝试一下。

You're doing this wrong. 您做错了。 You don't need to start rmid with arguments and system properties at all. 您根本不需要从参数和系统属性开始rmid All that stuff should be specified when you register the ActivationGroup(s) you're going to use, in your activation setup program. 在激活设置程序中注册要使用的ActivationGroup(s)时,应该指定所有这些东西。 That in turn means that all command-line problems should just disappear. 反过来,这意味着所有命令行问题都应该消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM