如何在IntelliJ中查看javap -c格式的Java字节码?
javap -c Style Bytecode in IntelliJ Without Full Project Compilation Great question! I totally feel your pain—IntelliJ's default bytecode viewer is way too verbose, and manually compiling classes just to run javap -c is a huge hassle. Here are a couple of straightforward ways to get clean javap -c output right in the IDE:
Option 1: Configure an External Tool (One-Time Setup, Easy Access)
This lets you right-click any Java class and instantly generate javap -c output:
- Open File > Settings > Tools > External Tools (on Mac, it's IntelliJ IDEA > Settings > Tools > External Tools)
- Click the
+button to add a new tool - Fill in the details:
- Name:
javap -c(or whatever you want to call it) - Program: Browse to your JDK's
javapexecutable (usually injdk/bin/javapon macOS/Linux,jdk\bin\javap.exeon Windows) - Arguments:
-c $FileClass$(this tellsjavapto disassemble the current class) - Working directory:
$OutputPath$(points to IntelliJ's compiled class files folder so it finds the .class file automatically)
- Name:
- Click OK to save the tool
Now, whenever you want to see javap -c output for a class:
- Right-click the Java file in the Project view or editor
- Hover over External Tools and select your
javap -ctool - The output will show up in the Run tab, formatted exactly like the
javap -ccommand line output
Option 2: Use a Custom Run Configuration
If you prefer using the IDE's run console, this method leverages Java's built-in sun.tools.javap.Main class:
- Go to Run > Edit Configurations
- Click the
+button and select Application - Configure the settings:
- Name:
javap -c Viewer - Main class: Enter
sun.tools.javap.Main - Program arguments:
-c your.package.name.YourClass(replace with the fully qualified name of the class you want to inspect) - Use classpath of module: Select the module where your class lives
- Name:
- Click OK
Before running this configuration, make sure the class is compiled (press Ctrl+F9 on Windows/Linux, Cmd+F9 on Mac—this compiles just the current module, not the entire project). Then run the configuration, and you'll see the familiar javap -c output in the console.
Pro tip: You can quickly edit the program arguments to switch between different classes without recreating the whole configuration.
Option 3: Quick Terminal Command (No Setup Needed)
If you don't want to mess with configurations, use IntelliJ's built-in terminal:
- First, compile the current class/module with
Ctrl+F9/Cmd+F9 - Open the terminal (bottom toolbar)
- Run this command (replace
your.package.YourClasswith your class's fully qualified name):javap -c $OutputPath$/your/package/YourClass.class
The $OutputPath$ variable is recognized by IntelliJ's terminal, so it automatically points to the correct compiled class folder.
All these methods let you avoid the clunky default bytecode viewer and skip full project compilations—perfect for inspecting just one or two classes quickly!
内容的提问来源于stack exchange,提问作者Nearoo

