IntelliJ 显示反编译的 .class 文件而不是源代码 [英] IntelliJ shows decompiled .class file instead of source code

查看:180
本文介绍了IntelliJ 显示反编译的 .class 文件而不是源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 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:

  1. Bytecode Viewer plugin is off.

  2. Java Bytecode Decompiler plugin is off.

  3. Platform, Project and Module all have same JDK version setup.

  4. 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

  5. src.zip is not corrupt - I can open it via WinRAR

  6. 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.

  7. Tried File > Invalidate Caches / Restart... - same result.

  8. Same issue in 2017.3 and fresh 2018.1 versions of IntelliJ.

  9. 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.

  10. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆