【问题标题】:REXEC Equivalent in GradleGradle 中的 REXEC 等价物
【发布时间】:2017-01-19 20:26:29
【问题描述】:

我正在开发一个从 Ant 转换为 Gradle 的构建。在其中,它必须与 IBM iSeries 系统交互以打包文件,然后将其下载回执行构建的机器 (Windows)。 FTP 部分很好,但我遇到问题的是 rexec 位。

在 Ant 中,我们可以使用 rexec 任务,而且效果很好。但是,我看不到 Gradle 方面的替代方案。这是我将不得不尝试使用 Groovy 编写脚本的东西吗?还是有一些我想念的替代方案?

【问题讨论】:

    标签: gradle groovy ant rexec


    【解决方案1】:

    如果 Gradle 不提供某些功能,通常会有一个插件。看看这个Gradle SSH plugin。它提供密码和证书认证。

    【讨论】:

      【解决方案2】:

      进一步研究表明rexec 不是 SSH。它是一个单独的远程协议,主要用于与 iSeries 交互。

      事实证明,我要做的是编写一个模仿 REXEC 功能的小程序。它利用IBM JT tools:

      package com.myco.mypackage;
      
      import java.beans.PropertyVetoException;
      import java.io.IOException;
      import com.ibm.as400.access.*;
      
      public class RemoteCommandExecutor {
      
          private String system;
          private String user;
          private String password;
          private String command;
      
          public RemoteCommandExecutor(String system, String user, String password, String command) {
              this.system = system;
              this.user = user;
              this.password = password;
              this.command = command;
          }
      
          public void doCmd (){
              AS400 theSys = new AS400(this.getSystem(), this.getUser(), this.getPassword());
              CommandCall cmd = new CommandCall(theSys);
              try {
                  cmd.run(this.getCommand());
                   AS400Message[] messageList = cmd.getMessageList();
                    for (int i = 0; i < messageList.length; i++) {
                       System.out.println(messageList[i].getText()); 
                    }
              } catch (AS400SecurityException 
                      | ErrorCompletingRequestException 
                      | IOException 
                      | InterruptedException
                      | PropertyVetoException e) {
                  e.printStackTrace();
              }
          }
      
          public static void main(String[] args) {
              RemoteCommandExecutor exec = new RemoteCommandExecutor(args[0],args[1],args[2], args[3]);
              exec.doCmd();
          }
      
          /**
           * @return the system
           */
          public String getSystem() {
              return system;
          }
      
          /**
           * @param system the system to set
           */
          public void setSystem(String system) {
              this.system = system;
          }
      
          /**
           * @return the user
           */
          public String getUser() {
              return user;
          }
      
          /**
           * @param user the user to set
           */
          public void setUser(String user) {
              this.user = user;
          }
      
          /**
           * @return the password
           */
          public String getPassword() {
              return password;
          }
      
          /**
           * @param password the password to set
           */
          public void setPassword(String password) {
              this.password = password;
          }
      
          /**
           * @return the command
           */
          public String getCommand() {
              return command;
          }
      
          /**
           * @param command the command to set
           */
          public void setCommand(String command) {
              this.command = command;
          }
      
      }
      

      然后从 build.gradle 中,做一个 exec 闭包...假设 jar 文件在项目中:

      exec{
            commandLine "java", "-jar", "RemoteCommandExecutor.jar", project.ext.props.get("system"), project.ext.props.get("user"),project.ext.props.get("password"), project.ext.props.get("command.to.run")
          }
      

      【讨论】:

        猜你喜欢
        • 2017-11-29
        • 1970-01-01
        • 2019-09-14
        • 1970-01-01
        • 1970-01-01
        • 2018-09-14
        • 2019-11-03
        • 1970-01-01
        • 2014-11-17
        相关资源
        最近更新 更多