"javap jar:file:" - Specify Bytecode in JAR

Q

How to specify Bytecode in a JAR file for the "javap" command?

✍: FYIcenter

A

If the bytecode is stored in *.class file, you can specify the bytecode for the "javap" command using the class file path name directly. For example:

> javap HelloWorldFrame.class
> javap \Users\fyicenter\HelloWorldFrame.class

If the bytecode is stored in *.jar file, you can specify the bytecode for the "javap" command using the "jar:file:" syntax:

> javap 'jar:file://absolute_path!/class_path'
> javap 'jar:file:relative_path!/class_path'

1. Compile HelloWorldFrame.java used in the last tutorial into a bytecode file, HelloWorldFrame.class:

> javac HelloWorldFrame.java 

2. Build a *.jar file with source code and bytecode:

> jar --create --file hello.jar HelloWorldFrame*.* 

> jar --list --file hello.jar 
META-INF/
META-INF/MANIFEST.MF
HelloWorldFrame$1.class
HelloWorldFrame.class
HelloWorldFrame.java

3. Run "javap" command on a bytecode in the *.jar file:

> javap 'jar:file:./hello.jar!/HelloWorldFrame.class'
Compiled from "HelloWorldFrame.java"
public class HelloWorldFrame extends javax.swing.JFrame {
  java.lang.String message;
  public HelloWorldFrame();
  public static void main(java.lang.String[]);
}

> javap 'jar:file:///Users/fyicenter/hello.jar!/HelloWorldFrame.class'
Compiled from "HelloWorldFrame.java"
public class HelloWorldFrame extends javax.swing.JFrame {
  java.lang.String message;
  public HelloWorldFrame();
  public static void main(java.lang.String[]);
}

 

⇒ Java Bytecode Tools

⇐ "javac -source 10 -target 10" - Lower Java Version

⇑ JDK "javap" Command

⇑⇑ Java Bytecode Tools

2021-09-09, 175👍, 0💬