JVisualVM: "Local Applications Cannot Be Detected" - java

I would like to monitor a local Java application using JVisualVM. When I'm starting it, the popup 'Local java application cannot be monitored' or 'Local Applications Cannot Be Detected' is shown. I have read here that it is a permissions problem. Every time when I grant full access to folder %TMP%hsperfdata_MY_USER_ID to me (logged user) and everyone (windows user), the permissions are reset when I start JVisualVM.
I know that another solution is to delete hsperfdata_MY_USER_ID, but why does the permissions trick not work? Is the permissions folder reset a Windows feature?
System : Windows 7
Tested on cmd started as administrator. I use the same accounts and I do not pass any JVM parameters such as com.sun.management.jmxremote.port=XXXX.

For people stumbling here who have a FAT-type file system:
Make a directory (e.g. e:\temp) on an NTFS disk.
Start both java and jvisualvm with an environment variable TMP=E:\temp.
There are three options to set the environment variable for java:
In your IDE, go to the project options or launch options and find the 'Environment' entry, then enter TMP=E:\temp
Open a cmd prompt, and execute set TMP=E:\temp before launching youur java application from the same prompt.
Put the two lines you'd enter at the cmd prompt in a .bat file. Optinally add pause at the end of the bat file to prevent the console window from disappearing in case of a runtime exception or vm crash.
Similarly, for JVisualVM, use one of the last two options.

I had the 'Local Applications Cannot Be Monitored' problem, got it solved like this:
Exit all java processes
Delete existing folder %TMP%\hsperfdata_username
Start jvisualvm, which created the folder with a different casing: %TMP%\hsperfdata_USERNAME
My problem and solution have nothing to do with permissions, so may not work for the original problem in the question.
Also see https://visualvm.github.io/troubleshooting.html#jpswin

This answer is a bit trivial but might still save time.
Check your java application is not lauched with the "-XX:-UsePerfData" option.

My username: A4000000
I had to delete C:\Users\A4000000\AppData\Local\Temp\hsperfdata_a4000000
AppData is a hidden folder.
Then once starting VisualVM again, it created the following:
C:\Users\A4000000\AppData\Local\Temp\hsperfdata_A4000000
Notice the case difference.
Then start:
C:\visualvm_213\bin> visualvm.exe --jdkhome "C:\Program Files\Java\jdk1.8.0_202" --userdir "C:\Temp\visualvm_userdir"

Related

Java autoconfigure startup execution at first launch

I'm trying to program something that, at first execution, in any OS could, set itself at startup OS programs list.
There are any library that do that? Or I should search how to do that in each OS?
I want to do an unique file, so I don't want to use scripts and anything.
For the moment I don't found any API for solve that.
In Unix system modifying (I think it could work in MAC, but not verified)
~/.profile <- User Privileges
/etc/profile <- With admin privileges
For Windows you can modify directly the key register
Run Java application at Windows startup
Or try to copy the program to the startup folder

Jar-File runs in console, but crahes when executed by batch-file

My programm uses a lot of memory, because it has to read huge .xls -Files.
So I added in Eclipse the argument -Xms512 and that works well for me.
The exported jar-file works the same when I run it from the commandline:
java -jar -Xms512 Excel_to_csv.jar
But when I run it with a .bat-file it runs, but crashes because of memory-problems:
java -jar -Xms512m Excel_to_csv.jar
I appreciate any ideas.
Fix the order of arguments: -jar expects the file name as argument but you give it -Xms. And saying "MB" probably is a good idea as well:
java -Xms512m -jar Excel_to_csv.jar
I'm not sure what the default is when you just say 512 but my guess would be KiB (meaning 512 KiB of RAM) which wouldn't be enough to even start the process.
That said, ms just sets the start amount of memory Java gets. If you process a complex Excel, you may need more memory. Try with
java -Xms512m -Xmx2000m -jar Excel_to_csv.jar
to allow Java to allocate as much as 2000 MiB when it has to.
I have an idea but I'm not sure. To use Xms parameter the user which is running the command must have the permission to lock pages in memory. Usually this right is granted to your user account. When you runc the command in command line it is running under your user account and everything works fine. When you pack the command into a batch file and start it, it is running under the account "SYSTEM". Now it's possible that this account doesn't have this permission (not sure about this point). To fix this do the following:
On the Start menu, click Run. In the Open box, type gpedit.msc.
On the Local Group Policy Editor console, expand Computer Configuration, and then expand Windows Settings.
Expand Security Settings, and then expand Local Policies.
Select the User Rights Assignment folder. The policies will be displayed in the details pane
In the pane, double-click Lock pages in memory.
In the Local Security Setting – Lock pages in memory dialog box, click Add User or Group.
In the Select Users, Service Accounts, or Groups dialog box, add the account "SYSTEM".
Log out and then log back in for this change to take effect.
taken (and modified) from https://msdn.microsoft.com/en-us/library/ms190730.aspx

Java.exe access is denied

I have problem with access to java.exe from not parent directory.
Windows Vista Home Premium, JDK 7.
I need to execute java.exe from any directory, but when I try to run it from Command Promt, I get message "Access is denied". I configured all related environment variables. Access rights to this file allow me to run it. All folders have read permissions.
If I run it from parent directory, everything is OK.
Does anybody know what's the problem?
I cannot think of any explanation apart from the obvious one; i.e. that in reality you have NOT configured the environment variables correctly for the command prompt.
You might have set the PATH variable incorrectly.
You might not have restarted the command shell after changing the environment variables.
(I don't think this can be a permissions issue if you can execute java.exe using the full pathname but not java.)
Try running cmd.exe with "Run As Administrator".
(2019) Necromancing...
Today I was happily doing some %JAVA_HOME%\BIN\KeyTool.exe, when suddenly a blue band over my screen appeared where it said that Access denied and that the program wasn't created for this platform. I had used KeyTool on this virtual machine over a 100 times?
This is how I stumbled upon this question.
Since internet didn't help my, I just uninstalled java, and re-installed it again, and Wham Bam Alakazam: it works again. So instead of searching what's wrong: just reinstall and within 4 minutes you're airborn again.

Need help running visualvm on Windows when under VMWare

I am doing some Java development on Windows 7 x64 running inside VMWare Fusion 3.x (OSX). I have installed JDK6 (update 26), set JAVA_HOME to the path (no trailing slash), and restarted my command prompt.
I can successfully launch the program. During startup it runs the calibration and then fails with this error:
"Could not create directory\VMWare-host\Shared Folders\ .nbprofiler" (no space after that slash but the markup was hiding the period)
I can click to continue, but when I'm in the program I cannot do CPU or Memory profiling. I throws up a similar error box:
"Error retrieving saved calibration data for target JVM: Could not create...(same as earlier)"
Once upon a time I had this working by passing the --userdir flag and -J-Dnbprofiler.home during startup, but that trick isn't working anymore.
(The complete command was:
jvisualvm --userdir c:\Users\myname -J-Dnbprofiler.home=c:\Users\myname
)
How can I force jvisualvm to save its calibration data on a "real" drive instead of the vmware network drive and get this working?
.nbprofiler directory is derived from user.home system property. I am not sure what you did to Windows installation, but your user.home points to directory\VMWare-host\Shared Folders. So one solution is to fix the Windows installation, so that Java recognize c:\Users\myname as your user home directory. If that fails for some reason you can use nbprofiler.home property to override it, as you correctly wrote. However you should point it to the nonexistent directory, so you should start VisualVM with the following commandline:
jvisualvm -J-Dnbprofiler.home=c:\Users\myname\nbprofiler --userdir c:\Users\myname\visualvm_userdir
One last note, even if the profiler part is not working, you should be able to use sampling in the 'Sampler' tab.
Try disable Sharing for the VM.
It works for me with Windows 7 x86 in Fusion with Sharing disabled (and Sharing is the mechanism providing the folder you cannot write to).
I found the following command works for me.
visualvm -J-Duser.home=%HOME%
Also, I needed to add -Duser.home=%HOME% to my app startup command.
I had defined nbprofile.home and userdir, but I was still getting an error when the Profiler was running against my app: Profiler Agent Error: Could not create directory\vmware-host\Shared Folders.nbprofiler.
I discovered that the Profiler was using user.home defined by my app rather than the one with visualvm. Both seem to be needed.

Windows Registery: How to add a Java app to startup list?

I added a value at:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
That looks like this:
Value Name: LDE
Value Data: "java -jar C:\LDE\lde.jar"
Really with the quotes (Because all the others where also with quotes). After adding this, I restarted my computer, but it didn't start automatically.
Will wrapping my jar in an exe help?
I'm running Windows 7.
Any help?
Thanks in advance.
Update:
When I remove the quotes, it works. But now there is appears also a terminal, which I don't need...
A couple of things to note here, concerning the two different issues in the problem:
Format of Windows Run keys
From the Microsoft Windows XP knowledge base:
Run keys cause programs to
automatically run each time that a
user logs on. The Windows XP registry
includes the following four Run keys:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
Each of these keys has a series of
values. The values allow multiple
entries to exist without overwriting
one another. The data value for a
value is a command line.
Note the emphasis on the last line. The moment quotes are used, the command is bound to fail execution in the same manner it fails as if executed from a command prompt.
Also, note that the above approach is for Windows XP and does hold good for Windows 7. More details can be found in this Microsoft Technet article on the options available in Windows 7.
The javaw vs java application launcher
Once the java process can be initialized at Windows startup, one will get a console window that continues to stay around until the process is terminated. This occurs if the java executable is utilized to initialize the application.
From the technotes of the java application launcher:
The javaw command is identical to
java, except that with javaw there is
no associated console window. Use
javaw when you don't want a command
prompt window to appear. The javaw
launcher will, however, display a
dialog box with error information if a
launch fails for some reason.
Therefore, if you wish to avoid opening a console window for the Java process, you ought to use the javaw executable.
This is very simple. You will find the startup folder in the C:/Documents and Settings/AllUsers/YourUserName/StartUp. It will be on similar kind of path just check it. Then just paste your jar file in that folder and it will work nice. Remember that you put the jar file in the startup folder of your user name folder. You may find that this folders might be hidden so just check it out. If you find this answer useful vote it. Enjoy.....

Categories