现象
使用jps不能查看java 的进程,使用visualVm不能监控到本地的java程序,并且提示"Local Applications Cannot Be Detected (Error Dialog On Startup)".
原因分析
java程序启动后,默认会在 %TEMP%/hsperfdata_%USERNAME% 目录下以该进程的id为文件名新建文件,并在该文件中存储jvm运行的相关信息,其中%TEMP%为wiondows系统的临时目录(在文件地址中输入"%TEMP%"即可跳转到此目录下);%USERNAME% 为当前的用户名(可通过cmd中输入echo %USERNAME% 查看).%TEMP%/hsperfdata_%USERNAME% 目录会存放该用户所有已经启动的java进程信息。
而jps、jconsole、jvisualvm等工具的数据来源就是这个文件(/%TEMP%/hsperfdata_%USERNAME%/pid)。所以当该文件不存在或是无法读取时就会出现jps无法查看该进程号.
解决
Local Applications Cannot Be Detected (Error Dialog On Startup)Description: An error dialog saying that local applications cannot be detected is shown immediately after VisualVM startup.
Resolution: This can happen on Windows systems, it's caused by misconfigured jvmstat technology used to detect the running applications. There are two possible causes:
Insufficient permissions for %TMP%\hsperfdata_username folder - make sure you're able to create a file in the directory and eventually update the permissions for full folder access. Alternatively you can just re-create the folder which should automatically set the correct access rights. See see this forums.sun.com thread for more details.
Having %TMP%\hsperfdata_username folder on a FAT disk - by default jvmstat doesn't work on FAT disks due to security restrictions. You can bypass the security check by setting the -XX:+PerfBypassFileSystemCheck flag for both VisualVM and the monitored application. See the JDK bug #5042659 for more details.(访问地址:点击打开链接)
--- https://visualvm.java.net/troubleshooting.html#jpswin