(자바RMI동영상)JAVA RMI를 이용하여 WAS(Tomcat) 기동/종료하기, RMI로 톰캣시작,종료하기

(자바RMI동영상)JAVA RMI를 이용하여 WAS(톰캣, Tomcat) 기동/종료하기  

 

 

이클립스 Java Project 생성 (프로젝트 이름 : rmi)

 

src아래 wasControl 패키지 생성

 

[WasControl.java]

package wasControl;

public interface WasControl extends Remote{

  public String startTomcat() throws Exception;

  public String stopTomcat() throws Exception;

 

}

 

[WasControlImpl.java]

public class WasControlImpl extends UnicastRemoteObject implements WasControl {

  static Runtime r = Runtime.getRuntime();

  static String tomcatPath = "C:/dev/apache-tomcat-9.0.37/bin";

  public WasControlImpl() throws RemoteException { super(); }

 

  public String startTomcat() throws Exception {

  String ret = "";

  try {

     Process tomcat = r.exec("cmd /c start " + tomcatPath + "/catalina.bat run", null, new File(tomcatPath));

     tomcat.waitFor();   //프로세스의 수행이 끝날 때까지 기다림

     ret = "Start OK...";

  } catch (Exception e) {

     System.out.println(">>>[Server]Tomcat Start Fail...." + e);  

     ret = "Start Fail...";

  }

 

  return ret;

  public String stopTomcat() throws RemoteException {

  String ret = "";

  try {

     Process tomcat =

                                      r.exec("cmd /c start " + tomcatPath + "/catalina.bat stop", null, new File(tomcatPath));

                                      tomcat.waitFor();
                                      ret = "Shutdown OK...";

  } catch (Exception e) {

     System.out.println(">>>[Server]Tomcat Start Fail...." + e);

     ret = "Shutdown Fail...";

  }

  return ret;

  }

 

}

 

[WasControlServer.java]

public class WasControlServer {

  public static void main(String[] args) {

  try {

     WasControlImpl remoteObj = new WasControlImpl();

     java.rmi.Naming.rebind("rmi://localhost:1099/WasControl", remoteObj);

     System.out.println(">>>[Server]Start, incoming client calls...");

  } catch (Exception e) {

     System.err.println(e);

  } 

  }

 

}

 

 

[WasControlClient.java]

public class WasControlClient {

  public static void main(String args[]) {

  try {

     Object obj = Naming.lookup("rmi://localhost:1099/WasControl");

        WasControl remoteObj = (WasControl) obj;

     // Tomcat Start

     String msg = remoteObj.startTomcat();   System.out.println(msg);

         Thread.currentThread().sleep(5000);

     // Tomcat End

     msg = remoteObj.stopTomcat();             System.out.println(msg);

  } catch (Exception e) {

     System.out.println("Something has gone wrong during remote method call...");

  }

  }

 

}

 

 

 

 

Project Name : rmi

WorkSpace : c:\dev\workspace

 

0. 컴파일은 이클립스에서 알아서

2. WasControlImpl_Stub 생성

C:\dev\workspace\rmi\bin>rmic wasControl.WasControlImpl

 

3. 네이밍 서비스 데몬 생성

C:\dev\workspace\rmi\bin>start rmiregistry 1099

 

4. 실행 : 서버 및 클라이언트는 이클립스에서 각각 Run AS ,  java application

 

5. 실행로그

Start OK...

Shutdown OK...

 

……

 

 

#RMI톰캣실행, #RMI톰캣구동, #자바톰캣실행, #자바톰캣구동, #자바동영상, #자바강의, #자바강좌, #자바RMI, #RMI강의, #RMI강좌, #RMI동영상, #JAVA강의, #JAVA, #JAVA강좌, #JAVARMI, #JAVA동영상

 

 

 

 

 

 

 

 

 

 

Comments