IntelliJ 显示反编译的 .class 文件而不是源代码 [英] IntelliJ shows decompiled .class file instead of source code
问题描述
我在使用 IntelliJ 时遇到问题 - 如果我按住 ctrl+单击该类,它会向我显示该类的反编译"版本,而不是其源代码.
这是我看到的:
我正在尝试打开常规 JDK 源文件.
我发现的最相关的问题解释如下:您的特定平台.
2.将 IntelliJ 指向源文件
在平台设置"→SDKs"→源路径"下的模块设置(使用F4打开)中,将包含JDK源代码的zip文件添加到您的项目JDK中(确保如果 IntelliJ 列出了多个 JDK,请选择正确的 JDK)使用带加号的按钮:
3.跳转到源码
选择一个 JDK 类,例如 Comparator
,使用 IntelliJ 的
I am having issues with IntelliJ - it shows me a "decompiled" version of the class instead of its source code if I ctrl+click the class.
This is what I see:
I am trying to open regular JDK source files.
The most relevant issue I found is explained here: Java sources replaced by decompiled files in Intellij
The most detailed answer I've found so far is there as well.
Yet it doesn't work for me:
Bytecode Viewer plugin is off.
Java Bytecode Decompiler plugin is off.
Platform, Project and Module all have same JDK version setup.
I have two JDKs available in IntelliJ: jdk1.8.0_161 and jbsdk8u112b287.2_windows_x86 (bundled with IntelliJ, but comes without src.zip). Tried with both (had to specify src.zip of jdk1.8.0_161 for jbsdk8u112b287.2_windows_x86) - no luck
src.zip is not corrupt - I can open it via WinRAR
When added jdk1.8.0_161 to IntelliJ, it automatically found src.zip. When manually adding src.zip to jbsdk8u112b287.2_windows_x86 Sourcepath tab - it started "Scanning for roots", but warned me that it "cannot determine what kind of files the chosen items contain" and offered me to "attach them as 'Sources'" so I agreed.
Tried File > Invalidate Caches / Restart... - same result.
Same issue in 2017.3 and fresh 2018.1 versions of IntelliJ.
Providing path for Documentation makes IntelliJ look for the documentation in the path specified. So it works as it should for both of JDKs. But not for sources.
Everything else works/compiles properly.
My settings:
1. Get the source files
Make sure you have downloaded and installed the source files of the JDK.
I'm on Arch Linux and installed them with pacman -S openjdk8-src
which put a src.zip
into /usr/lib/jvm/java-8-openjdk/
. We'll use that zip file in the next step.
To list source packages of different JDK versions, do pacman -Ss "openjdk.*-src"
.
See this question on how to get the source files for your specific platform.
2. Point IntelliJ to the source files
In your module settings (open them with F4) under "Platform Settings" → "SDKs" → "Sourcepath", add the zip file containing the JDK source to your project JDK (be sure to pick the right JDK if IntelliJ lists more than one JDK) using the button with the plus sign:
3. Jump into the source
Select a JDK class, like Comparator
, using IntelliJ's Search Everywhere or Ctrl+b with the cursor on the name of the class.
这篇关于IntelliJ 显示反编译的 .class 文件而不是源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!