2016-08-23 12 views
0

以前にmaven repoに公開されているgradleを使って、Webサーバーの1つにwarをデプロイするにはどうすればよいですか?それは貨物のプラグインで簡単にできますか?複数のリモート環境(DEV/TEST/PROD)を使用できますか?私は貨物を使ってリモートで展開してきましたが、それは生成された戦争と1つの「リモート」環境だけを使用してビルドの最後に行われました。レポからリモートサーバーにwarを展開する

入力はすべて役立ちます。

答えて

0

このコードはあなたに役立つと思います。 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()); 
      } 
     }  
    } 

ここで私は、JBossサーバーにxyz.warを展開しようとしています。 私はサーバーと認証をdeployments.propertiesファイルに保存しています。 warPathを取得し、このコードでCLIコマンドを実行しています。これにより、serverIPとserverPortを使用してリモートサーバーにwarを展開します。

このコードは私にとって役に立ちました。

関連する問題