Explorar o código

修复程序BUG。

YangZhiJie %!s(int64=8) %!d(string=hai) anos
pai
achega
72c794b114

+ 2 - 0
autoStart.bat

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

+ 27 - 14
config/applicationContext.xml

@@ -28,38 +28,51 @@
 
 	<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_20171218\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\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_20171218\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\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="applicationSetting3" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="工作流服务程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\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="applicationSetting4" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="钉钉服务程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\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="applicationSetting5" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="微信服务程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\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="applicationSetting6" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="中间件程序"></property>
-		<property name="startBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\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_20171218\start.bat"></property>
-		<property name="stopBatFile" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218\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="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

+ 84 - 8
src/main/java/com/leanwo/management/ServerManagmentJFrame.java

@@ -1,18 +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.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;
@@ -52,6 +64,9 @@ 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(boolean isAutoRun) {
@@ -61,7 +76,11 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 		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);
 		
@@ -73,12 +92,59 @@ 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;
         
@@ -166,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();
@@ -186,7 +253,8 @@ 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) {
 							logger.error("程序启动失败", e1);
@@ -204,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);
@@ -267,12 +340,15 @@ public class ServerManagmentJFrame extends JFrame implements ActionListener {
 				final ApplicationSetting setting = settings.get(i);
 				ExecuteWatchdog executeWatchdog;
 				try {
-					executeWatchdog = runProcess(setting.getStartBatFile());
-					boolean isWatch = executeWatchdog.isWatching();
-					if(! isWatch) {
-						logger.error("程序" + setting.getName() + "启动失败");
+					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);
 					}
-					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;
+	
 	/**
 	 * 应用程序状态.
 	 */
@@ -123,4 +128,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=BIN
src/main/java/com/leanwo/management/prodog_16.png


+ 8 - 3
src/main/java/org/leanwo/management/ServerManagementApp.java

@@ -3,7 +3,6 @@ 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.ProgramStartUtil;
 import org.leanwo.management.util.ProgramStopUtil;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
@@ -17,6 +16,8 @@ import com.leanwo.management.ServerManagmentJFrame;
 public class ServerManagementApp {
 	
 	private static Log logger = LogFactory.getLog(ServerManagmentJFrame.class);
+
+	
 	
 	public static void main(String[] args) {
 		//ProgramStartUtil.generateStartBat();
@@ -28,10 +29,14 @@ public class ServerManagementApp {
 			if(args[0].equals("autoRun")) {
 				isAutoRun = true;
 			}
+			for(String arg : args) {
+				logger.info("输出参数:" + arg);
+			}
 		}
 		
-		logger.info("程序管理器将会自动运行。");
-		
+		if(isAutoRun) {
+			logger.info("程序管理器将会自动运行。");
+		}
 		
 		ApplicationContext factory = new FileSystemXmlApplicationContext("config/applicationContext.xml");
 		ServerManagmentJFrame serverManagmentJFrame = new ServerManagmentJFrame(isAutoRun);