Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
700 views
in Technique[技术] by (71.8m points)

settings - IntelliJ shows decompiled .class file instead of source code

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:

Decompiled class message

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:

Settings

question from:https://stackoverflow.com/questions/49558009/intellij-shows-decompiled-class-file-instead-of-source-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

Sourcepath screenshot

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.

Comparator source


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...