To Java 20 in vscode

I trying to figur out how to change from /usr/lib/jvm/java-11-openjdk/bin/java to java-20-openjdk.
In vscode. java-20-openjdk is set as (default) on my system and in settings.json I try this without success:

    "java.configuration.runtimes": [
        {
            "name": "JavaSE",
            "path": "/usr/lib/jvm/default-runtime/bin/java",
            // "path": "/usr/lib/jvm/default/bin/java",
            "default": true
        }
    ],

also I try this in my zshrc :

# export JAVA_HOME="/usr/lib/jvm/default/bin/java"
    export JAVA_HOME="/usr/lib/jvm/default-runtime/bin/java"
    # export JAVA_HOME="/usr/lib/jvm/java-20-openjdk/bin/java"
    # export _JAVA_OPTIONS=-Djava.util.prefs.userRoot="$XDG_CONFIG_HOME"/java
    # export _JAVA_OPTIONS=-Djava.util.prefs.userRoot="/usr/lib/jvm/java-20-openjdk/bin/java"
    # export PATH="/usr/lib/jvm/default/bin/:$PATH"```
Any solution?

Did you test on console wehter your paths are correct ?

archlinux-java status
Available Java environments:
  java-11-openjdk
  java-17-openjdk
  java-20-openjdk
  java-20-openjdk-bin
  java-21-openjdk (default)
  java-8-openjdk
printenv|grep jvm
PATH=...in:/usr/lib/jvm/default/bin:/usr/bin/site_...
java -version
openjdk version "21-ea" 2023-09-19
OpenJDK Runtime Environment (build 21-ea+30-2426)
OpenJDK 64-Bit Server VM (build 21-ea+30-2426, mixed mode, sharing)
ls -l /usr/lib/jvm
insgesamt 8
lrwxrwxrwx 1 root root 15 19. Jun 20:58 default -> java-21-openjdk
lrwxrwxrwx 1 root root 15 19. Jun 20:58 default-runtime -> java-21-openjdk
drwxr-xr-x 1 root root 82 26. Mai 14:35 java-11-openjdk
drwxr-xr-x 1 root root 82 26. Mai 14:35 java-17-openjdk
drwxr-xr-x 1 root root 82 26. Mai 14:35 java-20-openjdk
drwxr-xr-x 1 root root 68 27. Apr 17:15 java-20-openjdk-bin
drwxr-xr-x 1 root root 68 10. Jul 21:05 java-21-openjdk
drwxr-xr-x 1 root root 60 26. Mai 14:36 java-8-openjdk

❯ echo $JAVA_HOME
/usr/lib/jvm/default/bin/java
❯ ls -lah /usr/lib/jvm/default/bin/ |g java

-rwxr-xr-x 1 root root  14K 24. Apr 23:38 javap
-rwxr-xr-x 1 root root  14K 24. Apr 23:38 javadoc
-rwxr-xr-x 1 root root  14K 24. Apr 23:38 javac
-rwxr-xr-x 1 root root  14K 24. Apr 23:38 java

❯ archlinux-java status

Available Java environments:
  java-11-openjdk
  java-17-openjdk
  java-20-openjdk (default)
  java-8-adoptopenjdk/jre
  java-8-openjdk

running java in the terminal gives me this:

java /home/$USER/ownCloud/java/aaTest/Age2.java
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel 
You are a Adult!
You are a Kid!

but on vscode I get the following:

 cd /home/$USER/ownCloud ; /usr/bin/env /usr/lib/jvm/java-11-openjdk/bin/java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:34229 -cp /home/$USER/.config/VSCodium/User/workspaceStorage/6bdbdf27bb4a57a3fcb6dbee2a0cf56d/redhat.java/jdt_ws/ownCloud_7802a30f/bin java.aaTest.Age2
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel 
  • I never used “path”: “/usr/lib/jvm/default-runtime/bin/java”,
  • In my IDE (eclipse) there is a separate configuration for every existing java-version
    • this way you can select the correct java version for every single project
  • eclipse uses the default java version to run eclipse
  • eclipse has configuration for every projekt to run this project with that jvm

I don´t know about vscode. :man_shrugging:

According to JAVA_HOME not set / Installation / Arch Linux Forums

JAVA_HOME hast to end with …/default not with /default/bin/java
This is the “home”-dir of java

In eclipse the Path to a jvm needs to end with …/java-xx-openjdk

I think the ide needs to get several infos about the jvm. so it need access to the home-folder of java (not to the java-binary)
:footprints:

1 Like

Also remove the commented line from JSON.

1 Like

Thank you so far,
I did reset the .JSON at Java › Configuration: Runtimes

  • also clear does:
export _JAVA_OPTIONS="" 
export JAVA_HOME=""
  • then try once with
    export JAVA_HOME=/usr/lib/jvm/default
    export JAVA_HOME=/usr/lib/jvm/java-20-openjdk and
    export JAVA_HOME=/usr/lib/jvm/default-runtime

running the “code runner” giving me this:

cd "/home/$USER/ownCloud/java/" && javac Age2.java && java Age2
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel 
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel  

and with the Java Debugger I get :

/usr/bin/env /usr/lib/jvm/java-11-openjdk/bin/java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:36757 -cp /home/$USER/.config/VSCodium/User/workspaceStorage/6bdbdf27bb4a57a3fcb6dbee2a0cf56d/redhat.java/jdt_ws/ownCloud_7802a30f/bin java.Age2
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel 

I don’t really know where _JAVA_OPTIONS is getting Picked up, but I’m now thinking the problem is somewhere in the setting of “Debugger for Java”

my java setting in launch.json is:

        {
            "type": "java",
            "name": "Java",
            "request": "launch",
            "mainClass": "${file}"
        },

I think your problem is

  • not manjaro-related
  • not linux related
  • not java related

BUT only related to vscode.

So you best look there for a solution :man_shrugging:

https://stackoverflow.com/questions/73145854/how-to-config-java-version-in-visual-studio-code

https://stackoverflow.com/questions/68957396/how-to-work-with-vscode-and-multiple-java-versions

it’s VS Code related, the problem was to set the right path in settings.json

this works now

"java.configuration.runtimes": [
		{
			"name": "JavaSE-20",
			"path": "/usr/lib/jvm/default",
			"default": true
		}
	]

thanks to everyone for the support

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.