【问题标题】:Deploy war from a repo onto remote server将战争从 repo 部署到远程服务器
【发布时间】:2016-08-24 14:19:47
【问题描述】:

如何使用之前发布到 maven 存储库的 gradle 将战争部署到其中一个 Web 服务器上? gradle 的 cargo 插件是否有助于它?我可以有多个远程环境(DEV/TEST/PROD)吗?我一直在使用 cargo 远程部署它,但这总是在构建结束时使用生成的战争完成,并且只使用一个“远程”环境。

任何输入都会有所帮助。

【问题讨论】:

    标签: gradle continuous-deployment cargo


    【解决方案1】:

    我认为这段代码会对你有所帮助。在 gradle 任务 runDeployment 上创建并运行任务:

    task runDeployment { 
        description 'deploy the war to the server'
    
        doLast {
            String serverIP;
            String serverPort;
            String userName;
            String password;
            String jbossPath;
            Properties prop = new Properties();
            InputStream input;
    
    
            try {
                input = new FileInputStream("deployment.properties");
                // load a properties file
                prop.load(input);
                // get the property value setting in the variables.
                serverIP = prop.getProperty("serverIP");
                serverPort = prop.getProperty("serverPort");
                userName = prop.getProperty("userName");
                password = prop.getProperty("password");
                jbossPath = prop.getProperty("jbossPath");
            } catch (IOException ex) {
                logger.info(ex.printStackTrace())
                throw new GradleException("Unable to load deployment.properties file. Exiting....")
            } finally {
                if (input != null) {
                    try {
                        input.close();
                    } catch (IOException e) {
    
                    }
                }
            }
    
    
    
                File file = new File("xyz/build/libs"); //path of the war location
                String warPath = file.getAbsolutePath();
    
                String[] comm = [jbossPath+"jboss-cli.bat","--connect","controller="+serverIP+":"+serverPort,"-u="+userName,"-p="+password, "--command=\"deploy","--force","xyz.war"];
                ProcessBuilder pb = new ProcessBuilder();
                pb.command(comm);
                pb.directory(new File(warPath));
                pb.inheritIO();    
                Process p = pb.start();
                try {
                     p.waitFor();
                } 
                catch (InterruptedException e) {
                     logger.info(e.printStackTrace());
                }
            }       
        }
    

    这里我尝试将 xyz.war 部署到 jboss 服务器。 我将服务器和身份验证保存在 deployments.properties 文件中。 我们将获得 warPath,并在此代码中运行 CLI 命令。这将使用 serverIP 和 serverPort 将战争部署到远程服务器。

    这段代码对我有用。

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 1970-01-01
      • 2010-11-01
      • 1970-01-01
      • 2014-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      相关资源
      最近更新 更多