设为首页 加入收藏

TOP

从零构建可视化jar包部署平台JarManage(二)
2023-07-25 21:34:17 】 浏览:57
Tags:从零构 jar 包部署 平台 JarManage
dLine(); 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服务

yml配置文件识别

  • 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内置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>
  • 手动启动
            //启动tomcat服务
            // 1.创建一个内嵌的Tomcat
            Tomcat tomcat = new Tomcat();
            // 2.设置Tomcat端口
            tomcat.setPort(8555);
            // 3.设置工作目录,tomcat需要使用这个目录进行写一些东西
            final String baseDir = "workspace" + File.separator;
            tomcat.setBaseDir(baseDir);
            tomcat.getHost().setAutoDeploy(false);
            // 4. 设置webapp资源路径
            String webappDirLocation = "webapp" + File.separator;
            StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
            // 5. 设置上下文路每径
            String contextPath = "";
            ctx.setPath(contextPath);
            ctx.addLifecycleListener(new
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Spring Boot 多数据源配置 下一篇IDEA项目下out与target目录的区别..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目