Vscode-java: Attach JDK source code

Created on 25 Oct 2018  ·  24Comments  ·  Source: redhat-developer/vscode-java

Environment
Current Result

I configured JAVA_HOME system environment variable, I also installed openjdk-11-source. And I can see the src.zip under the JAVA_HOME directory. But if I want to navigate to the definition of Class in standard java library, I always get:
// Failed to get sources. Instead, stub sources have been generated by the disassembler.
// Implementation of methods is unavailable.

Expected Result

It seems the vscode java extension use the eclipse jdt to handle java project. In eclipse, you can attach the src.zip to rt.zip. Then you can navigate to the JDK core class source code. Can this be done also in vscode?

Most helpful comment

OK, I found the root cause and solve the problem. Install through ubuntu apt official source,
apt install openjdk-11-source will install the src file to /usr/lib/jvm/openjdk-11/lib/src.zip. And then it creates an symbol link in the /usr/lib/jvm/java-11-openjdk-amd64. After check the link detail, I found the link actually linked to ../openjdk-11/src.zip, which is a broken link. I'm not sure if it's the apt problem, after deleting the symbol link and manually create a new link through sudo ln -s ../openjdk-11/lib/src.zip src.zip, problem solved.

All 24 comments

I believe it should just work. @snjeza can you please take a look?
Attaching random sources to jars/.class is something that should be covered by #233 .

One thing you can try, and it's a long shot, is to execute the "Java: clean the Java language workspace directory" command (from the command palette), now that the JDK has its sources, it should be picked up when the server workspace reinitializes.

Tried Java clean with no luck

The issue happens if we set java.home to JDK >=9 and open a project with a JRE container of the 8 version.
It can also be reproduced in Eclipse.

@praenubilus could you update your project's JRE to >= JRE 9 and restart VS Code.

The issue happens if we set java.home to JDK >=9 and open a project with a JRE container of the 8 version.
It can also be reproduced in Eclipse.

@praenubilus could you update your project's JRE to >= JRE 9 and restart VS Code.

I have jdk11 installed from ubuntu source, although it's jdk 10 actually. But it's > JRE9

What JRE container are you using in your project? Can you attach your .classpath?

What JRE container are you using in your project? Can you attach your .classpath?

I'm not sure about I understand what you mean about JRE container. I'm not using any container like docker. Also, this is just a single file workspace(not a maven/gradle project), there is no .classpath file as I can see.

Could you attach a project example?

I can't reproduce the issue.
Could you try the following:

  • enter Ctrl-Shift-P
  • select "Java: clean the Java language workspace directory"
  • click "Restart and delete"

I tried this yesterday and now. It does not solve the problem.

Could you try the following:

  • close VS Code
rm -rf ~/.config/Code/User/workspaceStorage/
  • start VS Code

Could you try the following:

  • close VS Code
rm -rf ~/.config/Code/User/workspaceStorage/
  • start VS Code

Not working. Is there any special environment variable need to be configured? I have java_home configured in my system.

Could you attach your log? See https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#turn-on-message-tracing-between-vs-code-and-the-java-language-server

Could you set the following:

"java.trace.server": "verbose"

and attach your log again

Could you set the following:

"java.trace.server": "verbose"

and attach your log again

I believe the previous one is verbose already. But in case I made mistake, I generate one again.
verbose.log

Could you, please, paste the contents of the Output view and attach it?

deleted

I double checked, the jrt-fs.jar is under directory with path /usr/lib/jvm/java-11-openjdk-amd64/lib/

OK, I found the root cause and solve the problem. Install through ubuntu apt official source,
apt install openjdk-11-source will install the src file to /usr/lib/jvm/openjdk-11/lib/src.zip. And then it creates an symbol link in the /usr/lib/jvm/java-11-openjdk-amd64. After check the link detail, I found the link actually linked to ../openjdk-11/src.zip, which is a broken link. I'm not sure if it's the apt problem, after deleting the symbol link and manually create a new link through sudo ln -s ../openjdk-11/lib/src.zip src.zip, problem solved.

OK, I found the root cause and solve the problem. Install through ubuntu apt official source,
apt install openjdk-11-source will install the src file to /usr/lib/jvm/openjdk-11/lib/src.zip. And then it creates an symbol link in the /usr/lib/jvm/java-11-openjdk-amd64. After check the link detail, I found the link actually linked to ../openjdk-11/src.zip, which is a broken link. I'm not sure if it's the apt problem, after deleting the symbol link and manually create a new link through sudo ln -s ../openjdk-11/lib/src.zip src.zip, problem solved.

In my case the @praenubilus approach did not work, the file src.zip, where the symbol link points, does not exist:

user@host:~$ whereis java
java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

user@host:~$ ll /usr/bin/java
lrwxrwxrwx 1 root root 22 Apr 26 00:24 /usr/bin/java -> /etc/alternatives/java*

user@host:~$ ll /etc/alternatives/java
lrwxrwxrwx 1 root root 43 Apr 26 00:24 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java*

user@host:~$ ll /usr/lib/jvm/java-11-openjdk-amd64/
total 48
drwxr-xr-x  9 root root  4096 May 14 20:49 ./
drwxr-xr-x  3 root root  4096 May 14 20:49 ../
drwxr-xr-x  2 root root  4096 May 14 20:49 bin/
drwxr-xr-x  4 root root  4096 May 14 20:49 conf/
lrwxrwxrwx  1 root root    42 Apr 16 23:00 docs -> ../../../share/doc/openjdk-11-jre-headless/
drwxr-xr-x  3 root root  4096 May 14 20:49 include/
drwxr-xr-x  2 root root 12288 May 14 20:49 jmods/
drwxr-xr-x 72 root root  4096 Apr 26 00:23 legal/
drwxr-xr-x  6 root root  4096 May 14 20:49 lib/
drwxr-xr-x  4 root root  4096 Apr 26 00:23 man/
-rw-r--r--  1 root root  1161 Apr 23 14:34 release
lrwxrwxrwx  1 root root    21 Apr 23 14:34 src.zip -> ../openjdk-11/src.zip # broken link

user@host:~$ ll /usr/lib/jvm/openjdk-11/lib/src.zip
ls: cannot access '/usr/lib/jvm/openjdk-11/lib/src.zip': No such file or directory

user@host:~$ ll /usr/lib/jvm/
total 16
drwxr-xr-x   3 root root 4096 May 14 20:49 ./
drwxr-xr-x 148 root root 4096 Jun 15 13:19 ../
lrwxrwxrwx   1 root root   21 Apr 16 23:00 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64/
-rw-r--r--   1 root root 1994 Apr 23 14:34 .java-1.11.0-openjdk-amd64.jinfo
drwxr-xr-x   9 root root 4096 May 14 20:49 java-11-openjdk-amd64/

user@host:~$ ll /usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip
ls: cannot access '/usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip': No such file or directory

user@host:~$ ll /usr/lib/jvm/java-11-openjdk-amd64/lib/
total 146460
drwxr-xr-x 6 root root      4096 May 14 20:49 ./
drwxr-xr-x 9 root root      4096 May 14 20:49 ../
-rw-r--r-- 1 root root     39425 Apr 23 14:34 classlist
-rw-r--r-- 1 root root   4489105 Apr 23 14:34 ct.sym
-rw-r--r-- 1 root root        63 Apr 23 14:34 jar.binfmt
-rwxr-xr-x 1 root root     14392 Apr 23 14:34 jexec*
drwxr-xr-x 2 root root      4096 May 14 20:49 jfr/
drwxr-xr-x 2 root root      4096 May 14 20:49 jli/
-rw-r--r-- 1 root root    106234 Apr 23 14:34 jrt-fs.jar
lrwxrwxrwx 1 root root        34 Apr 23 14:34 jvm.cfg -> /etc/java-11-openjdk/jvm-amd64.cfg
-rw-r--r-- 1 root root       278 Apr 23 14:34 jvm.cfg-default
lrwxrwxrwx 1 root root        47 Apr 23 14:34 libatk-wrapper.so -> ../../../x86_64-linux-gnu/jni/libatk-wrapper.so
-rw-r--r-- 1 root root     14504 Apr 23 14:34 libattach.so
-rw-r--r-- 1 root root     39216 Apr 23 14:34 libawt_headless.so
-rw-r--r-- 1 root root    700600 Apr 23 14:34 libawt.so
-rw-r--r-- 1 root root    396768 Apr 23 14:34 libawt_xawt.so
-rw-r--r-- 1 root root     22840 Apr 23 14:34 libdt_socket.so
-rw-r--r-- 1 root root     14392 Apr 23 14:34 libextnet.so
-rw-r--r-- 1 root root    712376 Apr 23 14:34 libfontmanager.so
-rw-r--r-- 1 root root     47296 Apr 23 14:34 libinstrument.so
-rw-r--r-- 1 root root     43088 Apr 23 14:34 libj2gss.so
-rw-r--r-- 1 root root     14456 Apr 23 14:34 libj2pcsc.so
-rw-r--r-- 1 root root     75880 Apr 23 14:34 libj2pkcs11.so
-rw-r--r-- 1 root root     14376 Apr 23 14:34 libjaas.so
-rw-r--r-- 1 root root     47408 Apr 23 14:34 libjavajpeg.so
-rw-r--r-- 1 root root    175232 Apr 23 14:34 libjava.so
-rw-r--r-- 1 root root     14032 Apr 23 14:34 libjawt.so
-rw-r--r-- 1 root root    249328 Apr 23 14:34 libjdwp.so
-rw-r--r-- 1 root root     31112 Apr 23 14:34 libjimage.so
-rw-r--r-- 1 root root     14440 Apr 23 14:34 libjsig.so
-rw-r--r-- 1 root root     68648 Apr 23 14:34 libjsound.so
-rw-r--r-- 1 root root     22856 Apr 23 14:34 liblcms.so
-rw-r--r-- 1 root root     14368 Apr 23 14:34 libmanagement_agent.so
-rw-r--r-- 1 root root     26864 Apr 23 14:34 libmanagement_ext.so
-rw-r--r-- 1 root root     22584 Apr 23 14:34 libmanagement.so
-rw-r--r-- 1 root root    567424 Apr 23 14:34 libmlib_image.so
-rw-r--r-- 1 root root     96904 Apr 23 14:34 libnet.so
-rw-r--r-- 1 root root     72592 Apr 23 14:34 libnio.so
-rw-r--r-- 1 root root     14328 Apr 23 14:34 libprefs.so
-rw-r--r-- 1 root root     14272 Apr 23 14:34 librmi.so
-rw-r--r-- 1 root root     47616 Apr 23 14:34 libsaproc.so
-rw-r--r-- 1 root root     30984 Apr 23 14:34 libsctp.so
-rw-r--r-- 1 root root     52136 Apr 23 14:34 libsplashscreen.so
-rw-r--r-- 1 root root    195432 Apr 23 14:34 libsunec.so
-rw-r--r-- 1 root root    107616 Apr 23 14:34 libunpack.so
-rw-r--r-- 1 root root     63936 Apr 23 14:34 libverify.so
-rw-r--r-- 1 root root     35168 Apr 23 14:34 libzip.so
-rw-r--r-- 1 root root 141038892 Apr 23 14:34 modules
lrwxrwxrwx 1 root root        41 Apr 23 14:34 psfontj2d.properties -> /etc/java-11-openjdk/psfontj2d.properties
lrwxrwxrwx 1 root root        41 Apr 23 14:34 psfont.properties.ja -> /etc/java-11-openjdk/psfont.properties.ja
drwxr-xr-x 2 root root      4096 May 14 20:49 security/
drwxr-xr-x 2 root root      4096 May 14 20:49 server/
lrwxrwxrwx 1 root root        37 Apr 23 14:34 swing.properties -> /etc/java-11-openjdk/swing.properties
-rw-r--r-- 1 root root    105734 Apr 23 14:34 tzdb.dat

The installation process was as follows:

user@host:~$ sudo apt install openjdk-11-jdk

user@host:~$ sudo vi /etc/environment
    ...
    JAVA_HOME=”/usr/lib/jvm/java-1.11.0-openjdk-amd64”
    ...

And I have as a result:

user@host:~$ echo $JAVA_HOME 
/usr/lib/jvm/java-1.11.0-openjdk-amd64

user@host:~$ $JAVA_HOME/bin/java --version
openjdk 11.0.3 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu219.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu219.04.1, mixed mode, sharing)

@kinlhp I think you also need following command:
sudo apt install openjdk-11-source

Just an update, they finally update the apt source to REAL jdk11. The same error symlink bug has been carried to latest version. And it has not been fixed yet, sad.

Hi @praenubilus, I follow this: https://github.com/redhat-developer/vscode-java/issues/993#issuecomment-513488225 .
Thanks.

Was this page helpful?
0 / 5 - 0 ratings