What version of javac built my jar?

前端 未结 20 955
孤街浪徒
孤街浪徒 2020-11-27 09:48

How can I tell what version of the Java compiler was used to build a jar? I have a jar file, and it could have been built in any one of three JDKs. We need to know exactly

20条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 10:29

    You can easily do this on command line using following process :

    If you know any of the class name in jar, you can use following command :

    javap -cp jarname.jar -verbose packagename.classname | findstr major
    

    example :

        C:\pathwherejarlocated> javap -cp jackson-databind-2.8.6.jar -verbose com.fasterxml.jackson.databind.JsonMappingException | findstr major
    

    Output :

        major version: 51
    

    Quick Reference :

    JDK 1.0 — major version 45 
    DK 1.1 — major version 45 
    JDK 1.2 — major version 46 
    JDK 1.3 — major version 47 
    JDK 1.4 — major version 48 
    JDK 1.5 — major version 49 
    JDK 1.6 — major version 50 
    JDK 1.7 — major version 51 
    JDK 1.8 — major version 52 
    JDK 1.9 — major version 53 
    

    PS : if you dont know any of the classname, you can easily do this by using any of the jar decompilers or by simply using following command to extract jar file :

    jar xf myFile.jar
    

提交回复
热议问题