检测JAR包JDK编译版本是否1.5
来源:互联网 发布:淘宝店铺推广技巧 编辑:程序博客网 时间:2024/06/08 11:41
所在项目的jdk版本是jdk1.5,而开源框架很多都升级到了1.6的版本,为了测试开源框架与现有jdk的兼容性,分享代码如下:
package org.myframework.jdbc;import java.io.BufferedReader;import java.io.DataInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;import java.util.zip.ZipInputStream;//The first 4 bytes are a magic number, 0xCAFEBABe, to identify a valid class file then the next 2 bytes identify the class format version (major and minor). //Possible major/minor value : //create table m2_lib ( library1 varchar2(100)) ;//select '"'||replace(library1,'\','/')||'",' from m2_lib ;////select * from m2_lib for update;//major minor Java platform version //45 3 1.0//45 3 1.1//46 0 1.2//47 0 1.3//48 0 1.4//49 0 1.5//50 0 1.6public class ClassVersionChecker { public static void main(String[] args) throws IOException { // for (int i = 0; i < args.length; i++) // checkClassVersion(args[i]); String[] jarsStrings = { "C:/Users/wanghui/.m2/repository/net/sf/ehcache/ehcache-core/2.4.8/ehcache-core-2.4.8.jar" }; for (int i = 0; i < jarsStrings.length; i++) scanJarFileJDK1_5_Version(jarsStrings[i]); } private static void checkClassVersion(String filename) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(filename)); int magic = in.readInt(); if (magic != 0xcafebabe) { System.out.println(filename + " is not a valid class!"); ; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); System.out.println(filename + ": " + major + " . " + minor); in.close(); } private static void checkClassVersion(InputStream in1) throws IOException { DataInputStream in = new DataInputStream(in1); int magic = in.readInt(); if (magic != 0xcafebabe) { System.out.println(in + " is not a valid class!"); ; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); System.out.println(": " + major + " . " + minor); in.close(); } private static void checkClassJDK1_5_Version(String jar,InputStream in1) throws IOException { DataInputStream in = new DataInputStream(in1); int magic = in.readInt(); if (magic != 0xcafebabe) { System.out.println(in + " is not a valid class!"); ; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); if (major >49) System.out.println(jar+": " + major + " . " + minor); in.close(); } public static void scanJarFileJDK1_5_Version(String zipname) { try { ZipInputStream zin = new ZipInputStream( new FileInputStream(zipname)); ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { if (entry.getName().endsWith(".class")) { ZipFile file = new ZipFile(zipname); InputStream in = file.getInputStream(entry); checkClassJDK1_5_Version(zipname,in); break; } } zin.close(); } catch (IOException e) { } } public static void scanZipFile(String zipname) { try { ZipInputStream zin = new ZipInputStream( new FileInputStream(zipname)); ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { System.out.println(entry.getName()); zin.closeEntry(); } zin.close(); } catch (IOException e) { } } public static void scanClassFile(String zipname) { try { ZipInputStream zin = new ZipInputStream( new FileInputStream(zipname)); ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { if (entry.getName().endsWith(".class")) { System.out.println(entry.getName()); ZipFile file = new ZipFile(zipname); InputStream in = file.getInputStream(entry); System.out.println(in); checkClassVersion(in); break; } } zin.close(); } catch (IOException e) { } } public static void loadZipFile(String zipname, String name) { try { ZipInputStream zin = new ZipInputStream( new FileInputStream(zipname)); ZipEntry entry; System.out.println(""); while ((entry = zin.getNextEntry()) != null) { if (entry.getName().equals(name)) { BufferedReader in = new BufferedReader( new InputStreamReader(zin)); String s; while ((s = in.readLine()) != null) System.out.println(s + "/n"); } zin.closeEntry(); } zin.close(); } catch (IOException e) { } }}
- 检测JAR包JDK编译版本是否1.5
- 怎么查看jar包的jdk编译版本
- 查看jar包中class的jdk编译版本
- 如何查看jar包的jdk版本
- 查看jar包的JDK版本
- 查看Jar包中Class类的编译环境jdk版本
- jdk 1.7环境下编译打包1.6版本的jar包
- 关于项目中所引用jar包的jdk编译版本
- 【异常】在hadoop集群上编译类jar包,因jdk版本不同出现的异常
- 配置maven下载jar包源码文件、拷贝依赖jar到lib包、设置编译时jdk版本、根据不同环境采用不同配置
- JAR包的JDK版本查看与设置
- JAR包的JDK版本查看与设置
- Spring Jar包因为JDK版本报错
- Hadoop运行jar包jdk版本冲突问题解决
- JAR包的JDK版本查看与设置
- JAR包的JDK版本查看与设置
- 将1.5版本编译的jar包降级转编译为1.4版
- java如何查看jar编译的jdk版本
- how-to-kill-the-running-job
- WF4.0 基础篇 (三) 流程实例WorkflowApplication与设计WF程序的基本原则
- 使用GIT管理自己的开源项目(工具篇)
- WINDOW下搭建GIT服务器和svn服务器
- SVN,GIT,VSS客户端代码目录
- 检测JAR包JDK编译版本是否1.5
- servlet 多线程
- SPRING MVC3.2案例讲解---配置
- SPRING MVC3.2案例讲解--SPRING定义欢迎首页
- Catalan数-hdu-3723-Delta Wave
- SPRING MVC3.2案例讲解--SPRING MVC3的各种URL映射(1)
- SPRING MVC3.2案例讲解--SPRING MVC3的各种URL映射(2)
- SPRING MVC3.2案例讲解--SPRING MVC3的各种URL映射+JSP视图跳转(3)
- Windows 会被 Linux 吃掉吗?