Przeglądaj źródła

依赖zhengAdmin

shuzheng 9 lat temu
rodzic
commit
0374166e33

+ 77 - 0
zheng-common/src/main/java/com/zheng/common/util/JarUtil.java

@@ -0,0 +1,77 @@
+package com.zheng.common.util;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * Created by shuzheng on 2016/12/18.
+ */
+public class JarUtil {
+
+    public static void main(String[] args) {
+        System.out.println("start");
+        decompress("F:\\GitHub\\zhengAdmin\\target\\zhengAdmin.jar", "F:\\GitHub\\zhengAdmin\\target\\test");
+        System.out.println("end");
+    }
+
+    /**
+     * 解压jar文件到指定目录
+     * @param fileName
+     * @param outputPath
+     */
+    public static synchronized void decompress(String fileName, String outputPath) {
+        // 保证输出路径为目录
+        if (!outputPath.endsWith(File.separator)) {
+            outputPath += File.separator;
+        }
+        // 如果不存在输出目录,则创建
+        File dir = new File(outputPath);
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+        // 解压到输出目录
+        JarFile jf = null;
+        try {
+            jf = new JarFile(fileName);
+            for (Enumeration<JarEntry> e = jf.entries(); e.hasMoreElements(); ) {
+                JarEntry je = (JarEntry) e.nextElement();
+                String outFileName = outputPath + je.getName();
+                File f = new File(outFileName);
+                if (je.isDirectory()) {
+                    if (!f.exists()) {
+                        f.mkdirs();
+                    }
+                } else {
+                    File pf = f.getParentFile();
+                    if (!pf.exists()) {
+                        pf.mkdirs();
+                    }
+                    InputStream in = jf.getInputStream(je);
+                    OutputStream out = new BufferedOutputStream(
+                            new FileOutputStream(f));
+                    byte[] buffer = new byte[2048];
+                    int nBytes = 0;
+                    while ((nBytes = in.read(buffer)) > 0) {
+                        out.write(buffer, 0, nBytes);
+                    }
+                    out.flush();
+                    out.close();
+                    in.close();
+                }
+            }
+        } catch (Exception e) {
+            System.out.println("解压" + fileName + "出错---" + e.getMessage());
+        } finally {
+            if (jf != null) {
+                try {
+                    jf.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+}

+ 7 - 3
zheng-upms/zheng-upms-server/pom.xml

@@ -19,7 +19,11 @@
             <groupId>com.zheng</groupId>
             <artifactId>zheng-upms-service</artifactId>
             <version>1.0.0</version>
-            <type>jar</type>
+        </dependency>
+        <dependency>
+            <groupId>com.github.shuzheng</groupId>
+            <artifactId>zhengAdmin</artifactId>
+            <version>1.0.0</version>
         </dependency>
         <dependency>
             <groupId>junit</groupId>
@@ -80,8 +84,8 @@
             <plugin>
                 <groupId>org.eclipse.jetty</groupId>
                 <artifactId>jetty-maven-plugin</artifactId>
-                <version>9.0.0.v20130308</version>
-                <!--<version>9.2.7.v20150116</version>-->
+                <!--<version>9.0.0.v20130308</version>-->
+                <version>9.2.7.v20150116</version>
                 <configuration>
                     <scanIntervalSeconds>3</scanIntervalSeconds>
                     <webApp>

+ 39 - 0
zheng-upms/zheng-upms-server/src/main/java/com/zheng/upms/admin/util/ZhengAdminUtil.java

@@ -0,0 +1,39 @@
+package com.zheng.upms.admin.util;
+
+import com.zheng.common.util.JarUtil;
+import com.zheng.common.util.PropertiesFileUtil;
+import com.zheng.upms.admin.controller.SSOController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.web.context.ServletContextAware;
+
+import javax.servlet.ServletContext;
+
+/**
+ * 启动解压zhengAdmin-x.x.x.jar到resources目录
+ * Created by shuzheng on 2016/12/18.
+ */
+public class ZhengAdminUtil implements InitializingBean, ServletContextAware {
+
+    private static Logger _log = LoggerFactory.getLogger(ZhengAdminUtil.class);
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+
+    }
+
+    @Override
+    public void setServletContext(ServletContext servletContext) {
+        _log.info("===== 开始解压zhengAdmin =====");
+        String version = PropertiesFileUtil.getInstance().get("zhengAdmin.version");
+        _log.info("zhengAdmin.jar 版本: {}", version);
+        String jarPath = servletContext.getRealPath("/WEB-INF/lib/zhengAdmin-" + version + ".jar");
+        _log.info("zhengAdmin.jar 包路径: {}", jarPath);
+        String resources = servletContext.getRealPath("/resources");
+        _log.info("zhengAdmin.jar 解压到: {}", resources);
+        JarUtil.decompress(jarPath, resources);
+        _log.info("===== 解压zhengAdmin完成 =====");
+    }
+
+}

+ 9 - 0
zheng-upms/zheng-upms-server/src/main/resources/applicationContext-zhengAdmin.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+
+	<!-- 启动解压zhengAdmin-x.x.x.jar到resources目录 -->
+	<bean id="zhengAdminUtil" class="com.zheng.upms.admin.util.ZhengAdminUtil"></bean>
+
+</beans>

+ 2 - 1
zheng-upms/zheng-upms-server/src/main/resources/config.properties

@@ -1 +1,2 @@
-env=${profile.env}
+env=${profile.env}
+zhengAdmin.version=1.0.0