最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

從零構(gòu)建可視化jar包部署平臺(tái)JarManage教程

 更新時(shí)間:2023年05月15日 11:39:32   作者:code2roc  
這篇文章主要為大家介紹了從零構(gòu)建可視化jar包部署平臺(tái)JarManage教程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

項(xiàng)目背景

在java項(xiàng)目部署過程中,由于內(nèi)外部各種因素,可能會(huì)遇到一些感覺操作不便捷的場景,例如

  • jar包未隨系統(tǒng)自動(dòng)啟動(dòng)需要每次手動(dòng)重啟
  • 系統(tǒng)vpn堡壘機(jī)多重防御更新繁瑣
  • 系統(tǒng)無圖形化界面命令行操作復(fù)雜
  • 等等......

在工作中之前也總結(jié)了windows的Jar包部署工具linux下的jar包自動(dòng)化部署腳本,這次就想著否能將二者統(tǒng)一結(jié)合,本著簡單/高效/功能專一的原則,做出一

個(gè)可視化jar包部署平臺(tái),JarManage應(yīng)運(yùn)而生

功能介紹

項(xiàng)目地址:https://gitee.com/code2roc/jar-manage

支持在線創(chuàng)建項(xiàng)目,上傳Jar包,自動(dòng)備份,配置啟動(dòng)參數(shù),注冊系統(tǒng)服務(wù),查看啟動(dòng)日志等功能,具有以下優(yōu)點(diǎn)

  • 基于servlet開發(fā),依賴簡潔,部署包10MB左右
  • 結(jié)合嵌入式tomcat一鍵部署,無外部容器依賴
  • 使用h2db存儲(chǔ)數(shù)據(jù),無外部數(shù)據(jù)庫依賴
  • 適配windows/linux平臺(tái),滿足多種環(huán)境
  • 具體項(xiàng)目經(jīng)平臺(tái)部署后自動(dòng)注冊系統(tǒng)服務(wù),無需擔(dān)心服務(wù)器重啟

系統(tǒng)架構(gòu)圖如下

系統(tǒng)截圖展示

技術(shù)分析

平臺(tái)識(shí)別

首先通過系統(tǒng)os識(shí)別是windows平臺(tái)還是linux平臺(tái)

String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("win")) {
   platform = DepolyPlatform.Windows;
}

通過system-release文件識(shí)別部分基于CentOS開發(fā)的Linux系統(tǒng)

String command = "cat /etc/system-release";
String result = CMDUtil.executeLinuxCommand(command);
if (result.startsWith("Red Hat")) {
   platform = DepolyPlatform.LinuxRedHat;
} else if (result.startsWith("CentOS")) {
   platform = DepolyPlatform.LinuxCentOS;
} else if (result.startsWith("openEuler")) {
   platform = DepolyPlatform.LinuxOpenEuler;
}

通過issue文件識(shí)別部分基于Ubuntu/Debian開發(fā)的Linux系統(tǒng)

command = "cat /etc/issue";
result = CMDUtil.executeLinuxCommand(command);
if (!StringUtil.isEmpty(result)) {
  if (result.startsWith("Ubuntu")) {
     platform = DepolyPlatform.LinuxUbuntu;
} else if (result.startsWith("Debian")) {
      platform = DepolyPlatform.LinuxDebian;
   }
}

windows注冊服務(wù)

通過sc query命令判斷服務(wù)狀態(tài)

public String getStatus(String serviceName) {
        String status = DepolyStatus.UnInstall;
        try {
            String command = "sc query " + serviceName;
            String commandResultFilePath = CMDUtil.executeWindowCommandStoreFile(command);
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(commandResultFilePath)));
            String line = reader.readLine();
            while (line != null) {
                if (line.trim().startsWith("STATE")) {
                    if (line.trim().substring(line.trim().indexOf(":") + 1, line.trim().indexOf(":") + 4).trim().equals("1"))
                        status = DepolyStatus.Stopped;
                    else if (line.trim().substring(line.trim().indexOf(":") + 1, line.trim().indexOf(":") + 4).trim().equals("2"))
                        status = DepolyStatus.Startting;
                    else if (line.trim().substring(line.trim().indexOf(":") + 1, line.trim().indexOf(":") + 4).trim().equals("3"))
                        status = DepolyStatus.Stopping;
                    else if (line.trim().substring(line.trim().indexOf(":") + 1, line.trim().indexOf(":") + 4).trim().equals("4"))
                        status = DepolyStatus.Running;
                }
                line = reader.readLine();
            }
        } catch (IOException e) {
            LogUtil.error(e);
        }
        return status;
    }

通過winsw這個(gè)開源項(xiàng)目配置exe和xml文件將jar包注冊為windows服務(wù),項(xiàng)目地址:https://github.com/winsw/winsw/

linux注冊服務(wù)

通過systemctl status命令判斷服務(wù)狀態(tài)

public String getStatus(String serviceName) {
        String status = DepolyStatus.UnInstall;
        try {
            String command = "systemctl status " + serviceName;
            String commandResultFilePath = CMDUtil.executeLinuxCommandWithStore(command);
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(commandResultFilePath)));
            String line = reader.readLine();
            while (line != null) {
                if (line.trim().startsWith("Active")) {
                    if (line.trim().indexOf("inactive (dead)") > 0)
                        status = DepolyStatus.Stopped;
                    else if (line.trim().indexOf("active (running)") > 0)
                        status = DepolyStatus.Running;
                    else if (line.trim().indexOf("failed") > 0)
                        status = DepolyStatus.Stopped;
                }
                line = reader.readLine();
            }
        } catch (IOException e) {
            LogUtil.error(e);
        }
        return status;
    }

通過拷貝service文件到systemd/system目錄下注冊linux服務(wù)

yml配置文件識(shí)別

  • maven配置
<dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>1.26</version>
        </dependency>
  • 配置文件
jarmanage:
  port: 8555
  username: admin
  password: abcd@1234
  backupcount: 5
  • 工具類
public static String getConfigValue(String configName){
        String configValue = "";
        try{
            Yaml yaml = new Yaml();
            InputStream resourceAsStream = new FileInputStream(new File("resources"+File.separator+"application.yml"));
            Map obj = yaml.load(resourceAsStream);
            Map<String,Object> param = (Map) obj.get("jarmanage");
            configValue = ConvertUtil.convert2String(param.get(configName));
        }catch (Exception e){
            LogUtil.error(e);
        }
        return configValue;
    }

h2database使用

  • maven引用
<dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>2.1.214</version>
        </dependency>
  • 工具類
public static Connection getConnection() throws Exception {
        File file = new File("database");
        Connection conn = DriverManager.getConnection("jdbc:h2:file:" + file.getAbsolutePath() + File.separator + "manage", "root", "abcd@1234");
        return conn;
    }
    public static void executeSQL(String sql) {
        try {
            Connection conn = getConnection();
            Statement stmt = conn.createStatement();
            stmt.execute(sql);
            stmt.close();
            conn.close();
        } catch (Exception e) {
            LogUtil.error(e);
        }
    }

servelt內(nèi)置tomcat打包

  • maven引用
<dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>9.0.35</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-el</artifactId>
            <version>9.0.35</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <version>9.0.35</version>
        </dependency>
  • 手動(dòng)啟動(dòng)
//啟動(dòng)tomcat服務(wù)
            // 1.創(chuàng)建一個(gè)內(nèi)嵌的Tomcat
            Tomcat tomcat = new Tomcat();
            // 2.設(shè)置Tomcat端口
            tomcat.setPort(8555);
            // 3.設(shè)置工作目錄,tomcat需要使用這個(gè)目錄進(jìn)行寫一些東西
            final String baseDir = "workspace" + File.separator;
            tomcat.setBaseDir(baseDir);
            tomcat.getHost().setAutoDeploy(false);
            // 4. 設(shè)置webapp資源路徑
            String webappDirLocation = "webapp" + File.separator;
            StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
            // 5. 設(shè)置上下文路每徑
            String contextPath = "";
            ctx.setPath(contextPath);
            ctx.addLifecycleListener(new Tomcat.FixContextListener());
            ctx.setName("jar-manage");
            tomcat.getHost().addChild(ctx);
            //6.啟動(dòng)
            tomcat.getConnector();
            tomcat.start();
            tomcat.getServer().await();
  • 打包包含引用類庫,自定義配置xml,指定運(yùn)行class
<plugins>
            <plugin>
                <!-- 打包包含引用 -->
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <!-- 自定義配置 -->
                        <descriptor>package.xml</descriptor>
                    </descriptors>
                    <archive>
                        <manifest>
                            <!-- 運(yùn)行類 -->
                            <mainClass>com.code2roc.jarmanage.Application</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.1 https://maven.apache.org/xsd/assembly-2.1.1.xsd">
    <!-- TODO: a jarjar format would be better -->
    <id>depoly</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <unpack>true</unpack>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>src/main/webapp/</directory>
            <outputDirectory>/webapp</outputDirectory>
            <includes>
                <include>**/**</include>
            </includes>
        </fileSet>

以上就是從零構(gòu)建可視化jar包部署平臺(tái)JarManage的詳細(xì)內(nèi)容,更多關(guān)于從零構(gòu)建可視化jar包部署平臺(tái)JarManage的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 關(guān)于springboot中對sqlSessionFactoryBean的自定義

    關(guān)于springboot中對sqlSessionFactoryBean的自定義

    這篇文章主要介紹了springboot中對sqlSessionFactoryBean的自定義方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • 啟動(dòng)Solr提示Java版本低問題解決方案

    啟動(dòng)Solr提示Java版本低問題解決方案

    這篇文章主要介紹了啟動(dòng)Solr提示Java版本低問題解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • 實(shí)例講解java定時(shí)任務(wù)

    實(shí)例講解java定時(shí)任務(wù)

    這篇文章主要介紹了實(shí)例講解java定時(shí)任務(wù),感興趣的的朋友可以參考下
    2015-08-08
  • Java?中很好用的數(shù)據(jù)結(jié)構(gòu)(你絕對沒用過)

    Java?中很好用的數(shù)據(jù)結(jié)構(gòu)(你絕對沒用過)

    今天跟大家介紹的就是?java.util.EnumMap,也是?java.util?包下面的一個(gè)集合類,同樣的也有對應(yīng)的的?java.util.EnumSet,對java數(shù)據(jù)結(jié)構(gòu)相關(guān)知識(shí)感興趣的朋友一起看看吧
    2022-05-05
  • SpringBoot數(shù)據(jù)訪問的實(shí)現(xiàn)

    SpringBoot數(shù)據(jù)訪問的實(shí)現(xiàn)

    本文主要介紹了SpringBoot數(shù)據(jù)訪問的實(shí)現(xiàn),引入各種xxxTemplate,xxxRepository來簡化我們對數(shù)據(jù)訪問層的操作,感興趣的可以了解一下
    2023-11-11
  • java實(shí)現(xiàn)新浪微博Oauth接口發(fā)送圖片和文字的方法

    java實(shí)現(xiàn)新浪微博Oauth接口發(fā)送圖片和文字的方法

    這篇文章主要介紹了java實(shí)現(xiàn)新浪微博Oauth接口發(fā)送圖片和文字的方法,涉及java調(diào)用新浪微博Oauth接口的使用技巧,具有一定參考接借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • 一文徹底弄懂spring?boot自動(dòng)配置的過程(推薦)

    一文徹底弄懂spring?boot自動(dòng)配置的過程(推薦)

    SpringBoot的自動(dòng)配置機(jī)制通過@SpringBootApplication注解作為起點(diǎn),結(jié)合@EnableAutoConfiguration和spring.factories文件,實(shí)現(xiàn)了基于類路徑依賴、環(huán)境配置和自定義代碼的智能化配置,感興趣的朋友跟隨小編一起看看吧
    2024-10-10
  • Spring MVC利用Swagger2如何構(gòu)建動(dòng)態(tài)RESTful API詳解

    Spring MVC利用Swagger2如何構(gòu)建動(dòng)態(tài)RESTful API詳解

    這篇文章主要給大家介紹了關(guān)于在Spring MVC中利用Swagger2如何構(gòu)建動(dòng)態(tài)RESTful API的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-10-10
  • Springboot 整合 Java DL4J 實(shí)現(xiàn)醫(yī)學(xué)影像診斷功能介紹

    Springboot 整合 Java DL4J 實(shí)現(xiàn)醫(yī)學(xué)影像診斷功能介紹

    本文介紹如何利用SpringBoot整合Java Deeplearning4j實(shí)現(xiàn)醫(yī)學(xué)影像診斷功能,重點(diǎn)介紹了卷積神經(jīng)網(wǎng)絡(luò)在處理醫(yī)學(xué)影像中的應(yīng)用,以及如何進(jìn)行數(shù)據(jù)預(yù)處理、模型構(gòu)建、訓(xùn)練與預(yù)測,提供了詳細(xì)的代碼實(shí)現(xiàn)和單元測試方法,目的是輔助醫(yī)生更準(zhǔn)確快速地進(jìn)行疾病診斷
    2024-10-10
  • Java面向?qū)ο缶幊讨惖睦^承詳解

    Java面向?qū)ο缶幊讨惖睦^承詳解

    這篇文章主要介紹了Java面向?qū)ο缶幊讨惖睦^承,結(jié)合實(shí)例形式較為詳細(xì)的分析了Java面向?qū)ο缶幊填惖母拍?、功能、使用方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2018-02-02

最新評(píng)論

肃南| 冀州市| 莎车县| 永修县| 随州市| 儋州市| 泾源县| 汉阴县| 孝昌县| 项城市| 平和县| 临猗县| 商洛市| 广州市| 宁国市| 永吉县| 灵武市| 怀集县| 游戏| 荔波县| 长沙县| 桑植县| 涟水县| 渭南市| 太康县| 那曲县| 封开县| 高阳县| 信丰县| 高陵县| 舞阳县| 海南省| 威信县| 揭东县| 新巴尔虎左旗| 宽城| 榕江县| 会泽县| 佛教| 新闻| 博湖县|