haoyanbing пре 8 година
родитељ
комит
41f8b30ebb

+ 2 - 0
.hgignore

@@ -2,3 +2,5 @@ syntax: glob
 *.class
 target/*
 *.log
+stop.bat
+start.bat

+ 2 - 0
autoStart.bat

@@ -0,0 +1,2 @@
+CD D:\LeanwoProgram_2017\ProdogV6\ServerManagement
+D:

+ 27 - 30
config/applicationContext.xml

@@ -22,60 +22,57 @@
 				<ref bean="applicationSetting5" />
 				<ref bean="applicationSetting6" />
 				<ref bean="applicationSetting7" />
-				<ref bean="applicationSetting8" />
 			</list>
 		</property>
 	</bean>
 
 	<bean id="applicationSetting1" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="Prodog服务程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\stop.bat"></property>
+		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
+	
 	<bean id="applicationSetting2" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="报表服务程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\stop.bat"></property>
-		<property name="monitorUrl" value="http://127.0.0.1:81/monitor"></property>
-		<property name="token" value="123456"></property>
+		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
+	
 	<bean id="applicationSetting3" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="工作流服务程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\stop.bat"></property>
-		<property name="monitorUrl" value="http://127.0.0.1:82/activiti/explorer/monitor"></property>
-		<property name="token" value="123456"></property>
+		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
+	
 	<bean id="applicationSetting4" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="钉钉服务程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\stop.bat"></property>
-		<property name="monitorUrl" value="http://127.0.0.1:83/monitor"></property>
-		<property name="token" value="123456"></property>
+		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
+	
 	<bean id="applicationSetting5" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="微信服务程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\stop.bat"></property>
-		<property name="monitorUrl" value="http://127.0.0.1:80/monitor"></property>
-		<property name="token" value="123456"></property>
+		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
+	
 	<bean id="applicationSetting6" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="中间件程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\stop.bat"></property>
+		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
+	
 	<bean id="applicationSetting7" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="抓拍程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171212\stop.bat"></property>
-	</bean>
-	<bean id="applicationSetting8" class="com.leanwo.management.model.ApplicationSetting">
-		<property name="name" value="文件服务程序"></property>
-		<property name="startBatFile" value=""></property>
-		<property name="stopBatFile" value=""></property>
-		<property name="monitorUrl" value="http://127.0.0.1:85/api/monitor"></property>
-		<property name="token" value="123456"></property>
+		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
 	
 	<bean id="springUtil" class="org.leanwo.management.util.SpringUtil" />

+ 3 - 0
config/killAllJava.bat

@@ -0,0 +1,3 @@
+taskkill /IM java.exe -t -f
+taskkill /IM javaw.exe -t -f
+pause

+ 2 - 2
config/run.bat

@@ -1,5 +1,5 @@
 title Report Server
 set current_path="%cd%"
 cd %current_path%
-java -jar %current_path%\report-server-0.0.1-SNAPSHOT.jar
-pause
+@echo off
+start javaw -jar %current_path%\ServerManagement-0.0.1-SNAPSHOT.jar

+ 11 - 0
config/schedule.bat

@@ -0,0 +1,11 @@
+@echo off
+set NAME=ProdogServerManagement
+set COMMAND=x:\xx\autoStart.bat
+
+%SystemDrive%
+cd %windir%\tasks\
+if exist %NAME%.job del %NAME%.job
+
+schtasks /create /tn %NAME% /tr "%COMMAND%" /sc onlogon
+
+pause

+ 1 - 4
pom.xml

@@ -116,9 +116,6 @@
 	                            </filter>  
 	                        </filters>
 							<transformers>
-								<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
-									<resource>jasperreports_extension.properties</resource>
-								</transformer>
 								<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
 									<resource>META-INF/spring.schemas</resource>
 								</transformer> 
@@ -127,7 +124,7 @@
 			                    </transformer>  
 								<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
 									<manifestEntries>
-										<Main-Class>com.leanwo.report.server.ReportServerApp</Main-Class>
+										<Main-Class>org.leanwo.management.ServerManagementApp</Main-Class>
 									</manifestEntries>
 								</transformer>
 							</transformers>

+ 116 - 43
src/main/java/com/leanwo/management/ServerManagmentJFrame.java

@@ -1,19 +1,30 @@
 package com.leanwo.management;
 
+import java.awt.AWTEvent;
+import java.awt.AWTException;
 import java.awt.BorderLayout;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
+import java.awt.Image;
 import java.awt.Insets;
+import java.awt.SystemTray;
 import java.awt.Toolkit;
+import java.awt.TrayIcon;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
-import java.util.Date;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.imageio.ImageIO;
 import javax.swing.BorderFactory;
 import javax.swing.JButton;
 import javax.swing.JFrame;
@@ -29,14 +40,6 @@ import org.apache.commons.exec.PumpStreamHandler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.leanwo.management.util.SpringUtil;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.http.client.SimpleClientHttpRequestFactory;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
-import org.springframework.web.client.RestTemplate;
 
 import com.leanwo.management.model.ApplicationSetting;
 import com.leanwo.management.model.ApplicationSettingCache;
@@ -61,16 +64,23 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 	private JPanel jPanel = null;
 	private Timer timer;
 
+	private TrayIcon trayIcon;				// 托盘图标
+	private SystemTray systemTray;	// 系统托盘
+	
 	private Map<ApplicationSetting, JLabel> statusLabels = null;
 	
-	public ServerManagmentJFrame() {
+	public ServerManagmentJFrame(boolean isAutoRun) {
 		this.setLayout(new BorderLayout());
 		
 		jPanel = new JPanel(new GridBagLayout());
 		this.add(jPanel, BorderLayout.NORTH);
         
 		this.setTitle("Prodog程序管理器");
-		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设定按关闭时的操作,这里是关闭窗口,如果不设定,就什么也不会发生
+		// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设定按关闭时的操作,这里是关闭窗口,如果不设定,就什么也不会发生
+
+        //激活窗口事件  
+        this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);  
+        
 		// 设置窗体位置和大小
 		this.setBounds((width - windowsWidth) / 2, (height - windowsHeight) / 2, windowsWidth, windowsHeight);
 		
@@ -81,8 +91,60 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 		
 		timer = new Timer(1000,this);
 		timer.start();
+		
+		// 判断当前平台是否支持系统托盘
+		if(SystemTray.isSupported()) {
+			// 获得系统托盘的实例
+			systemTray = SystemTray.getSystemTray();
+			try {
+				URL path = ServerManagmentJFrame.class.getResource("prodog_16.png");
+				Image imgae = ImageIO.read(path);   
+				trayIcon = new TrayIcon(imgae);
+				trayIcon.displayMessage("通知:", "程序最小化到系统托盘", TrayIcon.MessageType.INFO);
+				// 设置托盘的图标
+				systemTray.add(trayIcon);
+
+				trayIcon.addMouseListener(new MouseAdapter() {
+					public void mouseClicked(MouseEvent e) {
+						// 双击托盘窗口再现
+						if (e.getClickCount() == 2) {
+							boolean visible = isVisible();
+							// setExtendedState(Frame.NORMAL);
+							setVisible(!visible);
+						}							
+					}
+				});
+
+				this.addWindowListener(new WindowAdapter() {
+					public void windowIconified(WindowEvent e) {
+						// 窗口最小化时
+						setVisible(false);
+					}
+				});
+				
+			} catch (IOException e1) {
+				e1.printStackTrace();
+			} catch (AWTException e2) {
+				e2.printStackTrace();
+			}
+		}
+		
+		// 程序自动运行
+		if(isAutoRun) {
+			autoStart();
+		}
 	}
 
+	//重写这个方法  
+    @Override  
+    protected void processWindowEvent(WindowEvent e) {  
+        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
+        	setVisible(false);
+        	return;
+        }
+        super.processWindowEvent(e); //该语句会执行窗口事件的默认动作(如:隐藏)  
+    }  
+    
 	public void generateViewFromJson() {
 		GridBagConstraints constrains = null;
         
@@ -170,7 +232,8 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 					@Override
 					public void actionPerformed(ActionEvent e) {
 						try {
-							ExecuteWatchdog executeWatchdog = runProcess(setting.getStartBatFile());
+							String path = setting.getInstallPath() + File.separator + setting.getStartBatFile();
+							ExecuteWatchdog executeWatchdog = runProcess(path);
 							setting.setExecuteWatchdog(executeWatchdog);
 						} catch (IOException e1) {
 							e1.printStackTrace();
@@ -190,10 +253,11 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 					@Override
 					public void actionPerformed(ActionEvent e) {
 						try {
-							ExecuteWatchdog executeWatchdog = runProcess(setting.getStopBatFile());
+							String path = setting.getInstallPath() + File.separator + setting.getStopBatFile();
+							ExecuteWatchdog executeWatchdog = runProcess(path);
 							setting.setExecuteWatchdog(null);
 						} catch (IOException e1) {
-							e1.printStackTrace();
+							logger.error("程序启动失败", e1);
 						}
 					}
 				});
@@ -208,6 +272,11 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 	 * @throws IOException
 	 */
 	private ExecuteWatchdog runProcess(String command) throws IOException {
+		if(command == null || command.length() == 0) {
+			return null;
+		}
+		logger.info("即将运行命令:" + command);
+		
 		final CommandLine cmdLine = CommandLine.parse(command);
 		
 		final ExecuteWatchdog watchDog = new ExecuteWatchdog(Long.MAX_VALUE);
@@ -223,7 +292,7 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 		
 		//等待5秒。
 		try {
-			resultHandler.waitFor(5000);
+			resultHandler.waitFor(2000);
 		} catch (InterruptedException e) {
 			e.printStackTrace();
 		}
@@ -248,38 +317,42 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 					if(executeWatchdog == null) {
 						statusLabel.setText("未运行");
 					}else{
-						statusLabel.setText("运行中");
+						if(executeWatchdog.isWatching()) {
+							statusLabel.setText("运行中");					
+						}else {
+							statusLabel.setText("已停止");		
+						}
 					}
 				}
-				
-				// 监控各个服务程序是否正在运行
-				String url = setting.getMonitorUrl();
-				String token = setting.getToken();
-				if(url == null || "".equals(url) || token == null || "".equals(token)){
-					continue;
-				}
-				RestTemplate restTemplate = new RestTemplate();		
-				restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
-				HttpHeaders headers = new HttpHeaders();
-				headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
-				headers.add("account", "2");
-				headers.add("token", token);
-				HttpEntity entity = new HttpEntity(headers);
-				try{			
-					ResponseEntity<Long> response = restTemplate.exchange(url, HttpMethod.GET, entity, Long.class);
-					((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(1000*30);
-					((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(1000*30);
-					Long result = response.getBody();
-					long mills = new Date().getTime() - result;
-					if(statusLabel != null){
-						statusLabel.setText("运行中(" + mills + "ms)");
-					}
-				}catch(Exception ex){
-					if(statusLabel != null){
-						statusLabel.setText("已停止");
+			}
+		}
+	}
+	
+	/**
+	 * 程序自动运行
+	 */
+	private void autoStart() {
+		ApplicationSettingCache applicationSettingCache = (ApplicationSettingCache) SpringUtil.getSingleBean(ApplicationSettingCache.class);
+
+		List<ApplicationSetting> settings = applicationSettingCache.getSettings();
+		if (settings != null && settings.size() > 0) {
+			for(int i = 0; i < settings.size(); i ++) {
+				final ApplicationSetting setting = settings.get(i);
+				ExecuteWatchdog executeWatchdog;
+				try {
+					String path = setting.getInstallPath() + File.separator + setting.getStartBatFile();
+					executeWatchdog = runProcess(path);
+					if(executeWatchdog != null) {
+						boolean isWatch = executeWatchdog.isWatching();
+						if(! isWatch) {
+							logger.error("程序" + setting.getName() + "启动失败");
+						}
+						setting.setExecuteWatchdog(executeWatchdog);
 					}
+				} catch (IOException e) {
+					logger.error("程序" + setting.getName() + "启动失败", e);
 				}
 			}
 		}
-	}	
+	}
 }

+ 23 - 0
src/main/java/com/leanwo/management/model/ApplicationSetting.java

@@ -14,6 +14,11 @@ public class ApplicationSetting {
 	 */
 	private String name;
 
+	/**
+	 * 安装路径.
+	 */
+	private String installPath;
+	
 	/**
 	 * 应用程序状态.
 	 */
@@ -165,4 +170,22 @@ public class ApplicationSetting {
 	public void setExecuteWatchdog(ExecuteWatchdog executeWatchdog) {
 		this.executeWatchdog = executeWatchdog;
 	}
+
+	/**
+	 * Gets the 安装路径.
+	 *
+	 * @return the 安装路径
+	 */
+	public String getInstallPath() {
+		return installPath;
+	}
+
+	/**
+	 * Sets the 安装路径.
+	 *
+	 * @param installPath the new 安装路径
+	 */
+	public void setInstallPath(String installPath) {
+		this.installPath = installPath;
+	}
 }

BIN
src/main/java/com/leanwo/management/prodog_16.png


+ 1 - 1
src/main/java/log4j.properties

@@ -5,7 +5,7 @@ log4j.appender.A1.layout=org.apache.log4j.PatternLayout
 log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} [%c]-[%p] %m%n
 
 log4j.appender.R=org.apache.log4j.RollingFileAppender 
-log4j.appender.R.File=logs/report-server.log
+log4j.appender.R.File=logs/server-management.log
 log4j.appender.R.MaxFileSize=500KB
 log4j.appender.R.MaxBackupIndex=1
 log4j.appender.R.layout=org.apache.log4j.PatternLayout 

+ 27 - 2
src/main/java/org/leanwo/management/ServerManagementApp.java

@@ -1,5 +1,9 @@
 package org.leanwo.management;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.leanwo.management.util.ProgramAutoStartUtil;
+import org.leanwo.management.util.ProgramStopUtil;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 
@@ -10,10 +14,31 @@ import com.leanwo.management.ServerManagmentJFrame;
  *
  */
 public class ServerManagementApp {
+	
+	private static Log logger = LogFactory.getLog(ServerManagmentJFrame.class);
+
+	
+	
 	public static void main(String[] args) {
-		ApplicationContext factory = new FileSystemXmlApplicationContext("config/applicationContext.xml");
-		ServerManagmentJFrame serverManagmentJFrame = new ServerManagmentJFrame();
+		//ProgramStartUtil.generateStartBat();
+		ProgramAutoStartUtil.generateStartBat();
+		ProgramStopUtil.generateStopBat();
 		
+		boolean isAutoRun = false;
+		if(args != null && args.length > 0) {
+			if(args[0].equals("autoRun")) {
+				isAutoRun = true;
+			}
+			for(String arg : args) {
+				logger.info("输出参数:" + arg);
+			}
+		}
 		
+		if(isAutoRun) {
+			logger.info("程序管理器将会自动运行。");
+		}
+		
+		ApplicationContext factory = new FileSystemXmlApplicationContext("config/applicationContext.xml");
+		ServerManagmentJFrame serverManagmentJFrame = new ServerManagmentJFrame(isAutoRun);
 	}
 }

+ 66 - 0
src/main/java/org/leanwo/management/util/ProgramAutoStartUtil.java

@@ -0,0 +1,66 @@
+package org.leanwo.management.util;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * 程序启动通用类
+ * 
+ * @author YangZhiJie
+ *
+ */
+public class ProgramAutoStartUtil {
+	private static Log logger = LogFactory.getLog(ProgramAutoStartUtil.class);
+
+	/**
+	 * 生成停止程序的BAT文件
+	 */
+	public static void generateStartBat() {
+		File file = new File("autoStart.bat");
+		if (file.exists() == false) {
+			try {
+				file.createNewFile();
+			} catch (IOException e) {
+				logger.error("autoStart.bat文件创建失败.");
+				e.printStackTrace();
+			}
+		}
+
+		logger.info("autoStart.bat文件的路径如下:" + file.getAbsolutePath());
+
+		try {
+			BufferedWriter out = new BufferedWriter(new FileWriter(file, false));
+			String path = file.getAbsolutePath().replace(File.separatorChar + file.getName(), "");
+			
+			String command = "CD " + path + "\r\n";
+			String diskName = path.substring(0, path.indexOf(":") + 1);
+			command += (diskName + "\r\n");
+			
+
+			File pathFolder = new File(path);
+			File[] files = pathFolder.listFiles(new FileFilter() {
+				@Override
+				public boolean accept(File pathname) {
+					if (pathname.isFile() && pathname.getName().endsWith(".jar")) {
+						return true;
+					}
+					return false;
+				}
+			});
+			
+			if(files != null && files.length > 0) {
+				command += ("start javaw -jar " + files[0].getName() + " autoRun");
+			}
+			out.write(command);
+			out.close();
+		} catch (IOException e) {
+			logger.error("autoStart.bat文件写入失败。");
+		}
+	}
+}

+ 66 - 0
src/main/java/org/leanwo/management/util/ProgramStartUtil.java

@@ -0,0 +1,66 @@
+package org.leanwo.management.util;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * 程序启动通用类
+ * 
+ * @author YangZhiJie
+ *
+ */
+public class ProgramStartUtil {
+	private static Log logger = LogFactory.getLog(ProgramStartUtil.class);
+
+	/**
+	 * 生成停止程序的BAT文件
+	 */
+	public static void generateStartBat() {
+		File file = new File("start.bat");
+		if (file.exists() == false) {
+			try {
+				file.createNewFile();
+			} catch (IOException e) {
+				logger.error("start.bat文件创建失败.");
+				e.printStackTrace();
+			}
+		}
+
+		logger.info("start.bat文件的路径如下:" + file.getAbsolutePath());
+
+		try {
+			BufferedWriter out = new BufferedWriter(new FileWriter(file, false));
+			String path = file.getAbsolutePath().replace(File.separatorChar + file.getName(), "");
+			
+			String command = "CD " + path + "\r\n";
+			String diskName = path.substring(0, path.indexOf(":") + 1);
+			command += (diskName + "\r\n");
+			
+
+			File pathFolder = new File(path);
+			File[] files = pathFolder.listFiles(new FileFilter() {
+				@Override
+				public boolean accept(File pathname) {
+					if (pathname.isFile() && pathname.getName().endsWith(".jar")) {
+						return true;
+					}
+					return false;
+				}
+			});
+			
+			if(files != null && files.length > 0) {
+				command += ("javaw -jar " + files[0].getName());
+			}
+			out.write(command);
+			out.close();
+		} catch (IOException e) {
+			logger.error("start.bat文件写入失败。");
+		}
+	}
+}

+ 58 - 0
src/main/java/org/leanwo/management/util/ProgramStopUtil.java

@@ -0,0 +1,58 @@
+package org.leanwo.management.util;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * 程序关闭通用类
+ * @author YangZhiJie
+ *
+ */
+public class ProgramStopUtil {
+	private static Log logger = LogFactory.getLog(ProgramStopUtil.class);
+
+	/**
+	 * 生成停止程序的BAT文件
+	 */
+	public static void generateStopBat() {
+		File file = new File("stop.bat");
+		if(file.exists() == false) {
+			try {
+				file.createNewFile();
+			} catch (IOException e) {
+				logger.error("stop.bat文件创建失败.");
+				e.printStackTrace();
+			}
+		}
+		
+		logger.info("stop.bat文件的路径如下:" + file.getAbsolutePath());
+		
+		try {
+	         BufferedWriter out = new BufferedWriter(new FileWriter(file, false));
+	         String command = "taskkill /pid " + getPid() + " -t -f";
+	         out.write(command);
+	         out.close();
+		} catch (IOException e) {
+			logger.error("stop.bat文件写入失败。");
+		}
+	}
+	
+	/**
+	 * 获取PID
+	 * @return
+	 */
+	private static String getPid() {
+		// get name representing the running Java virtual machine.    
+		String name = ManagementFactory.getRuntimeMXBean().getName();    
+		// get pid    
+		String pid = name.split("@")[0];    
+		logger.debug("Pid is:" + pid);
+		return pid;
+	}
+}