package com.cronos.admin.tomcat;

import java.io.IOException;
import java.net.URL;

public class RestartTomcatThread implements Runnable {

	public void run() {

		String catalinaBase = System.getProperty("catalina.base");
		// String catalinaHome = System.getProperty("catalina.home");

		URL path = RestartTomcat.class.getProtectionDomain().getCodeSource().getLocation();
		String sPath = path.getPath();
		String clasesPath = sPath.substring(0, sPath.indexOf("classes")) + "classes";

		/*
		 * ESTO SE USABA PARA EL BOOTSTRAP PERO AL FINAL NO SE UTILIZA, SE LLAMA AL
		 * "NET STAT" O BIEN A LOS .SH/.BAT
		 * 
		 * String binTomcat = catalinaHome + File.separator + "bin"; String bootstrap =
		 * binTomcat + File.separator + "bootstrap.jar"; String juli = binTomcat +
		 * File.separator + "tomcat-juli.jar"; String classpath = "\"" + clasesPath +
		 * ":" + bootstrap + ":" + juli + "\"";
		 */

		String pack = RestartTomcatThread.class.getPackage().toString();
		String claseRestart = pack.replaceAll("package ", "") + ".RestartTomcat";

		try {
			Runtime.getRuntime().exec("java -cp " + clasesPath + " " + claseRestart + " \"" + catalinaBase + "\"");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}