You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Visualvm does not honor the JAVA_HOME variable. Having to start it with "bin/visualvm --jdkhome $JAVA_HOME" is an unneccessary annoyance.
Describe the solution you'd like
If JAVA_HOME is set, then visualVM should use it as the default value for the jdkhome.
If it is not set, visualvm should behave as it does today.
Describe alternatives you've considered
None
Additional context
JAVA_HOME is used by most Java startup scritps to locate the JRE to be used.
Developers expect JAVA_HOME to be honored, and is usually set correctly on developer machines by jenv, sdkman, etc.
Reacted by Fernando D. Bozzo, Tyler Crawford, Dmitry Taimanov and Bob Riverfinch
@stoty Can you, please, describe in which situation you rely on JAVA_HOME? The current state is there for a long time, so it would be useful to know your use case. Note that NetBeans Platform code is primarily responsible for finding the JDK, so the problem should be ideally fixed there.
The JVM is chosen by the startup bash script on Unix, which chooses the JVM for running visualvm.
I'm not sure what you mean by the NetBeans platform code.
Possibly visualvm is started differently when it is started as a NetBeans module (as opposed to the standalone visualvm startup script) , but then this patch does not apply in that case.
I am working on multiple versions of multiple projects, which require different java versions, and use jenv to switch between them. All of my other tools (well, except for Eclipse) honor the JAVA_HOME environment variable.
Also, this patch only aligns the unix startup script behaviour with the existing Windows behaviour, which already honor JAVA_HOME (see my comment above with the commit )
I'm not sure what you mean by the NetBeans platform code.
If you do not specify JDK explicitly, it is chosen by NetBeans platform code, not by VisualVM launcher script.
I am working on multiple versions of multiple projects, which require different java versions
I see, but you are not required to run VisualVM on the same JDK as your project. VisualVM can simultaneously monitor Java processes running on different JDKs (JDK 6 up to JDK 24), so the JDK on which VisualVM is running has no connection to the JDK of your monitored processes.
patch only aligns the unix startup script behaviour with the existing Windows
Windows is a different story. The GH-112 fix in Windows is basically a workaround for VisualVM not starting at all in some situations (see discussion at GH-112). Again, on Windows, the JDK should be chosen by the NetBeans Platform code. Currently there are some historical changes in VisualVM Windows launcher regarding JDK selection, but they are unrelated to JDK_HOME. So unless this is a critical problem, I do not want to apply a similar workaround to the Unix launcher in VisualVM.
It looks like NetBeans Platform updated the Windows code to consider JAVA_HOME (See NB-8408) so GH-112 could be removed once we update VisualVM to use NetBeans Platform 26.
If you do not specify JDK explicitly, it is chosen by NetBeans platform code, not by VisualVM launcher script.
That does not match my experience.
If you do not add the cli option or set it in the command line, then VisualVM will not find any JVM, and will not start.
General options:
--help show this help
--jdkhome <path> path to Java(TM) 2 SDK, Standard Edition
-J<jvm_option> pass <jvm_option> to JVM
--cp:p <classpath> prepend <classpath> to classpath
--cp:a <classpath> append <classpath> to classpath
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Cannot find java. Please use the --jdkhome switch.
From visualvm script we are composeing the arguments & delegate to nbexec
If you do not specify JDK explicitly, it is chosen by NetBeans platform code, not by VisualVM launcher script.
That does not match my experience. If you do not add the cli option or set it in the command line, then VisualVM will not find any JVM, and will not start.
It works fine. In general, you are not required to specify the JDK. Of course there could be system configuration, when JDK is not found. That is why I asked for your use-case.
You are right, it makes sense to fix this problem there, and remove the redundant JAVA_HOME code from 'visualvm"
Seems like nbexec simply is just unaware of the existence of non Apple Unix OSs.
(and even the MacOS logic could use some improvments)
Right, but I was never talking about visualvm.exe.
Either the bash script finds a java and uses it to start visualvm/netbeans or it fails.
Right, but there are two scripts. bin/visualvm startup script does not search for jdk. The second script platform/lib/nbexec is responsible for launching java binary and can find the JDK if you do not specify it. The fact that it fails for you does not mean that it fails for everyone.
🕙 [09:11:10] ❯ echo $JAVA_HOME
/Users/work/.local/share/mise/installs/java/25.0.2
🕙 [09:17:08] ❯ java --version
openjdk 25.0.2 2026-01-20
OpenJDK Runtime Environment (build 25.0.2+10-69)
OpenJDK 64-Bit Server VM (build 25.0.2+10-69, mixed mode, sharing)
🕙 [09:17:02] ❯ /Applications/VisualVM.app/Contents/MacOS/visualvm
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Cannot find java. Please use the --jdkhome switch.
It works fine if I specify jdkhome:
🕙 [09:18:48] ❯ /Applications/VisualVM.app/Contents/MacOS/visualvm --jdkhome /Users/work/.local/share/mise/installs/java/25/
WARNING: package com.sun.java.swing.plaf.gtk not in java.desktop
WARNING: package sun.awt.X11 not in java.desktop
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::loadLibrary has been called by com.sun.jna.Native in an unnamed module (jar:file:/Applications/VisualVM.app/Contents/Resources/visualvm/platform/modules/ext/jna-5.14.0.jar!/)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
-------------------------------------------------------------------------------
>Log Session: Friday, April 10, 2026, 9:19:26 AM Central European Summer Time
>System Info:
Product Version = VisualVM 2.2.1
Operating System = Mac OS X version 15.7.4 running on aarch64
Java; VM; Vendor = 25.0.2; OpenJDK 64-Bit Server VM 25.0.2+10-69; Oracle Corporation
Runtime = OpenJDK Runtime Environment 25.0.2+10-69
Java Home = /Users/work/.local/share/mise/installs/java/25.0.2
System Locale; Encoding = en_ES (visualvm); UTF-8
Home Directory = /Users/work
Current Directory = /Users/work
User Directory = /Users/work/Library/Application Support/VisualVM/2.2.1
Cache Directory = /Users/work/Library/Caches/VisualVM/2.2.1
Installation = /Applications/VisualVM.app/Contents/Resources/visualvm/visualvm
/Applications/VisualVM.app/Contents/Resources/visualvm/platform
…
Version 2.2.1 lists this issue in its release notes, so I'm not sure why it's not picking the JDK from th environment variable.
Activity
dasarathirout commentedon Jul 20, 2025
we can add configure visualvm_jdkhome in visualvm/etc/visualvm.conf file, then visualvm need no addinational arguments to run
stoty commentedon Jul 28, 2025
Yes, but setting that is still a separate setup step, so it doesn' really solve the issue.
stoty commentedon Jul 28, 2025
This has already been fixed for Windows in #112
stoty commentedon Jul 28, 2025
So the logic / JVM precendence could be copied from there to make sure that it behaves consistently between Unix and Windows.
dasarathirout commentedon Jul 31, 2025
PR #643 Added JAVA_HOME to visulavm luncher & conf
thurka commentedon Aug 6, 2025
@stoty Can you, please, describe in which situation you rely on
JAVA_HOME? The current state is there for a long time, so it would be useful to know your use case. Note that NetBeans Platform code is primarily responsible for finding the JDK, so the problem should be ideally fixed there.stoty commentedon Aug 6, 2025
I am using the standalone visualvm distribution.
The JVM is chosen by the startup bash script on Unix, which chooses the JVM for running visualvm.
I'm not sure what you mean by the NetBeans platform code.
Possibly visualvm is started differently when it is started as a NetBeans module (as opposed to the standalone visualvm startup script) , but then this patch does not apply in that case.
I am working on multiple versions of multiple projects, which require different java versions, and use jenv to switch between them. All of my other tools (well, except for Eclipse) honor the JAVA_HOME environment variable.
Also, this patch only aligns the unix startup script behaviour with the existing Windows behaviour, which already honor JAVA_HOME (see my comment above with the commit )
thurka commentedon Aug 6, 2025
If you do not specify JDK explicitly, it is chosen by NetBeans platform code, not by VisualVM launcher script.
I see, but you are not required to run VisualVM on the same JDK as your project. VisualVM can simultaneously monitor Java processes running on different JDKs (JDK 6 up to JDK 24), so the JDK on which VisualVM is running has no connection to the JDK of your monitored processes.
Windows is a different story. The GH-112 fix in Windows is basically a workaround for VisualVM not starting at all in some situations (see discussion at GH-112). Again, on Windows, the JDK should be chosen by the NetBeans Platform code. Currently there are some historical changes in VisualVM Windows launcher regarding JDK selection, but they are unrelated to
JDK_HOME. So unless this is a critical problem, I do not want to apply a similar workaround to the Unix launcher in VisualVM.It looks like NetBeans Platform updated the Windows code to consider
JAVA_HOME(See NB-8408) so GH-112 could be removed once we update VisualVM to use NetBeans Platform 26.stoty commentedon Aug 6, 2025
That does not match my experience.
If you do not add the cli option or set it in the command line, then VisualVM will not find any JVM, and will not start.
stoty commentedon Aug 6, 2025
also, there is heuristics in the VisualVM laucher script to find the JVM.
dasarathirout commentedon Aug 6, 2025
visualvm script call to
nbexecscript which exepect --jdkhomeargument./nbexec --helpUsage: ./nbexec {options} arguments
From visualvm script we are composeing the arguments & delegate to
nbexecthurka commentedon Aug 8, 2025
It works fine. In general, you are not required to specify the JDK. Of course there could be system configuration, when JDK is not found. That is why I asked for your use-case.
thurka commentedon Aug 8, 2025
VisualVM launcher does not require JDK. If you do not specify it, the
nbexecinvocation looks like this:stoty commentedon Aug 8, 2025
There is no visualvm.exe for unix.
Either the bash script finds a java and uses it to start visualvm/netbeans or it fails.
dasarathirout commentedon Aug 9, 2025
nbexec#L130-L179 script checking jdk location , but it is not considering JAVA_HOME env var to be used as jdkhome.
stoty commentedon Aug 11, 2025
Thanks @dasarathirout .
You are right, it makes sense to fix this problem there, and remove the redundant JAVA_HOME code from 'visualvm"
Seems like nbexec simply is just unaware of the existence of non Apple Unix OSs.
(and even the MacOS logic could use some improvments)
stoty commentedon Aug 11, 2025
Actually, it is aware (there is a default case), but it ignores JAVA_HOME, and the symlink resolution code doesn't work with jenv style shims.
thurka commentedon Aug 11, 2025
Right, but I was never talking about
visualvm.exe.Right, but there are two scripts.
bin/visualvmstartup script does not search for jdk. The second scriptplatform/lib/nbexecis responsible for launching java binary and can find the JDK if you do not specify it. The fact that it fails for you does not mean that it fails for everyone.stoty commentedon Aug 11, 2025
Please see apache/netbeans#8725 @thurka .
thurka commentedon Aug 11, 2025
.. and this is the right place for the fix. I already mentioned it here: #623 (comment)
neilcsmith-net commentedon Aug 18, 2025
The right place for any platform application to have alternative launcher behaviour to the default is first and foremost its own launch script!
GH-623 incorporate NetBeans fix
thurka commentedon Feb 7, 2026
Done in master.
woj-tek commentedon Apr 10, 2026
(I'm not sure if it's better to open new issue or comment in this one but for consistency I'll comment in here).
Giving more context to @thurka :
I'm using
mise(https://mise.jdx.dev/) to manage java installation. It handles setting up environment (includingJAVA_HOME) and in general works well everywhere. However, for some reason it doesn't work with VisualVM.It works fine if I specify
jdkhome:Version 2.2.1 lists this issue in its release notes, so I'm not sure why it's not picking the JDK from th environment variable.
thurka commentedon Apr 10, 2026
@woj-tek It looks like the backported fix does not cover macOS. Please file separate issue. Thanks.
woj-tek commentedon Apr 10, 2026
Done. Thank you for confirming :)