当前位置: 首页 > news >正文

网页与网站之间的关系全网热搜榜第一名

网页与网站之间的关系,全网热搜榜第一名,番禺24小时核酸检测,高端营销网站一、简述 Maven项目通过package打成jar包后,jar包中包含所有依赖lib文件。本文介绍了两种方式解析嵌套jar中的class文件,一种是通过spring-boot-loader包JarFileArchive,另一种是util包中JarFile。 二、JarFileArchive方式 1.spring-boot-…

一、简述

Maven项目通过package打成jar包后,jar包中包含所有依赖lib文件。本文介绍了两种方式解析嵌套jar中的class文件,一种是通过spring-boot-loader包JarFileArchive,另一种是util包中JarFile。

二、JarFileArchive方式

1.spring-boot-loader依赖引入

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-loader</artifactId><version>2.2.4.RELEASE</version>
</dependency>

 2.demo案例

   public static void main(String args[]) throws Exception {String jarPath = "C:\\Users\\root\\Desktop\\make-test.jar";// 方案一:spring-boot-loaderlong start1 = System.currentTimeMillis();getClassInfoByJarLib(jarPath);long end1 = System.currentTimeMillis();log.info("收集所有lib类ClassInfo,花费时间={}",(end1-start1));} public static void getClassInfoByJarLib(String jarPath) {String filePath = "file:/"+ URLDecoder.decode(jarPath, StandardCharsets.UTF_8).replaceAll("\\\\","/")+"!/";String rootJarPath = "jar:"+ filePath;try {JarFileArchive jarFileArchive = new JarFileArchive(new Handler().getRootJarFileFromUrl(new URL(rootJarPath)));//getNestedArchives获取嵌套的jar等文件,参数是个EntryFilter,过滤条件jarFileArchive.getNestedArchives(entry -> entry.getName().startsWith("BOOT-INF/lib/") && entry.getName().endsWith(".jar")).forEach(archive -> {archive.iterator().forEachRemaining(entry -> {String entryName = entry.getName();// 过滤嵌套jar包中字节码文件if (entryName.endsWith(".class")) {String className = entryName.replace('/', '.').replace(".class", "");log.info("className:{}",className);}});});} catch (IOException e) {log.error("解析嵌套jarLib中ClassInfo异常,jarPath={}",jarPath,e);throw new RuntimeException(e);}}

三、JarFile方式

1.demo案例 

   public static void main(String args[]) throws Exception {String jarPath = "C:\\Users\\root\\Desktop\\make-test.jar";// 方案二:JarFilelong start2 = System.currentTimeMillis();processJar(jarPath);long end2 = System.currentTimeMillis();log.info("收集所有lib类ClassInfo,花费时间={}",(end2-start2));} private static void processJar(String jarPath){try (JarFile jarFile = new JarFile(new File(jarPath))) {jarFile.stream().parallel()// 过滤出所有符合要求的jar包.filter(entry -> !entry.isDirectory() && entry.getName().startsWith("BOOT-INF/lib/") && entry.getName().endsWith(".jar")).forEach(entry -> processNestedJar(jarFile, entry.getName()));} catch (IOException e) {log.error("解析嵌套jarLib中ClassInfo异常,jarPath={}",jarPath,e);throw new RuntimeException(e);}}private static void processNestedJar(JarFile jarFile, String entryName){// 处理嵌套jar文件try (InputStream nestedJarStream = jarFile.getInputStream(jarFile.getJarEntry(entryName));JarInputStream jarInputStream = new JarInputStream(nestedJarStream)) {JarEntry nestedEntry;while ((nestedEntry = jarInputStream.getNextJarEntry()) != null) {if (nestedEntry.isDirectory()) {continue;}String nestedEntryName = nestedEntry.getName();if (!nestedEntryName.endsWith(".class")) {continue;}try {String className = nestedEntryName.replace('/', '.').replace(".class", "");log.info("className:{}",className);} catch (Exception e) {log.error("目标类={}查找失败",nestedEntryName,e);throw new RuntimeException(e);}}} catch (IOException e) {log.error("目标类={}查找失败",entryName,e);throw new RuntimeException(e);}}

四、两种方式对比

实测项目make-test.jar中所有依赖lib约200个,其中所有class字节码文件约7万多个。方案JarFileArchive约1.5s全部解析,方案JarFile约6s全部解析。

http://www.hkea.cn/news/258727/

相关文章:

  • 做的网站显示图片很慢百度运营公司
  • 青州哪里做网站公司推广渠道
  • 网站面包屑导航怎么做的网推接单平台有哪些
  • 宜昌网站建设兼职百度关键词排名软件
  • 如何让百度快照找到自己的网站营销策划方案ppt模板
  • php网站超市广告软文是什么意思
  • b2c跨境电商宣城网站seo
  • 网站建设一流公司免费网站开发平台
  • 网站开发模式名词外贸谷歌优化
  • 网站素材 下载产品推广渠道
  • 网站后台维护怎么做seo专员工资一般多少
  • 中国网站推广黄页名录微商推广哪家好
  • 哈尔滨网站开发电话电商培训基地
  • 如何用php数据库做网站搜索seo优化托管
  • 中国城乡建设部人力网站首页优化落实疫情防控
  • 做网站到底能不能赚钱网络优化工程师前景
  • 乌镇网站建设标书百度站长工具域名查询
  • 制作公司网站价格腾讯广告代理商加盟
  • 大学生活动网站开发文案苏州seo门户网
  • 阿里云认证网站建设题库seo助理
  • 凤岗网站仿做靠谱seo外包定制
  • xampp安装wordpress说明徐州seo外包
  • 啥网站都能看的浏览器下载百度收录查询工具
  • 福田附近公司做网站建设哪家效益快奶糖 seo 博客
  • 临沂免费自助建站模板品牌整合营销
  • iis做本地视频网站找客户资源的网站
  • 做调查用哪个网站网络推广有多少种方法
  • 开发一个交易网站多少钱在线工具
  • 网站平台怎么建立的软文范例
  • 移动应用开发专业学什么东莞seo软件