You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在IntelliJ中查看javap -c格式的Java字节码?

How to View 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 javap executable (usually in jdk/bin/javap on macOS/Linux, jdk\bin\javap.exe on Windows)
    • Arguments: -c $FileClass$ (this tells javap to disassemble the current class)
    • Working directory: $OutputPath$ (points to IntelliJ's compiled class files folder so it finds the .class file automatically)
  • 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 -c tool
  • The output will show up in the Run tab, formatted exactly like the javap -c command 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
  • 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:

  1. First, compile the current class/module with Ctrl+F9/Cmd+F9
  2. Open the terminal (bottom toolbar)
  3. Run this command (replace your.package.YourClass with 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:18:05