コード例 #1
0
  public static GeneralCommandLine setupJVMCommandLine(
      final String exePath,
      final SimpleJavaParameters javaParameters,
      final boolean forceDynamicClasspath) {
    final GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(exePath);

    final ParametersList vmParametersList = javaParameters.getVMParametersList();
    commandLine.getEnvironment().putAll(javaParameters.getEnv());
    commandLine.setPassParentEnvironment(javaParameters.isPassParentEnvs());

    appendParamsEncodingClasspath(javaParameters, commandLine, vmParametersList);

    final String mainClass = javaParameters.getMainClass();
    String jarPath = javaParameters.getJarPath();
    if (mainClass != null) {
      commandLine.addParameter(mainClass);
    } else if (jarPath != null) {
      commandLine.addParameter("-jar");
      commandLine.addParameter(jarPath);
    }

    commandLine.addParameters(javaParameters.getProgramParametersList().getList());

    commandLine.withWorkDirectory(javaParameters.getWorkingDirectory());

    log.debug("starting process with commandLine: " + commandLine.getCommandLineString());

    return commandLine;
  }
コード例 #2
0
 private static void appendParamsEncodingClasspath(
     SimpleJavaParameters javaParameters,
     GeneralCommandLine commandLine,
     ParametersList parametersList) {
   commandLine.addParameters(parametersList.getList());
   appendEncoding(javaParameters, commandLine, parametersList);
   if (!parametersList.hasParameter("-classpath")
       && !parametersList.hasParameter("-cp")
       && !javaParameters.getClassPath().getPathList().isEmpty()) {
     commandLine.addParameter("-classpath");
     commandLine.addParameter(javaParameters.getClassPath().getPathsString());
   }
 }
コード例 #3
0
 private static void appendEncoding(
     SimpleJavaParameters javaParameters,
     GeneralCommandLine commandLine,
     ParametersList parametersList) {
   // Value of file.encoding and charset of GeneralCommandLine should be in sync in order process's
   // input and output be correctly handled.
   String encoding = parametersList.getPropertyValue("file.encoding");
   if (encoding == null) {
     Charset charset = javaParameters.getCharset();
     if (charset == null) charset = EncodingManager.getInstance().getDefaultCharset();
     commandLine.addParameter("-Dfile.encoding=" + charset.name());
     commandLine.withCharset(charset);
   } else {
     try {
       Charset charset = Charset.forName(encoding);
       commandLine.withCharset(charset);
     } catch (UnsupportedCharsetException ignore) {
     } catch (IllegalCharsetNameException ignore) {
     }
   }
 }