2016-08-23 4 views
0

이전에 maven repo에 웹 서버 중 하나에 게시 된 gradle을 사용하여 전쟁을 배포 할 수 있습니까? 그래 플에 대한화물 플러그인으로 쉽게 처리 할 수 ​​있습니까? 여러 원격 환경 (DEV/TEST/PROD)을 가질 수 있습니까? 나는 그것을 원격으로 배치하기 위해화물을 사용 해왔다. 그러나 그것은 생성 된 전쟁과 하나의 "원격"환경만을 사용하여 빌드가 끝날 때 항상 수행되었다.repo에서 원격 서버로 전쟁 배포

모든 입력이 도움이 될 것입니다.

답변

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가있는 원격 서버에 전쟁이 전개됩니다.

이 코드는 저에게 효과적입니다.