简体   繁体   中英

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. 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. The problem is that it won't allow me to specify multiple JARs for the codebase property on Linux. 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. On Windows, the working line looks like this:

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. 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. My shell script looks like the following:

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. 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. 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.

Instead of "" to produce a quote inside quotes, you have to use \\" in 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. It's probably either file:// or the absolute file path without anything preceding it, but you'll have to try it out.

You're doing this wrong. You don't need to start rmid with arguments and system properties at all. All that stuff should be specified when you register the ActivationGroup(s) you're going to use, in your activation setup program. That in turn means that all command-line problems should just disappear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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