cannot start jstatd due to permission error
Just found following script to run jstatd
. I managed to run jstatd
with this script
https://gist.github.com/nicerobot/1375032
#!/bin/sh
policy=${HOME}/.jstatd.all.policy
[ -r ${policy} ] || cat >${policy} <<'POLICY'
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
POLICY
jstatd -J-Djava.security.policy=${policy} &
This is what worked for me:
Make sure that tools.jar file exists and the user running the jstatd command has permissions to read it.
Make sure that the URL in the
jstatd.all.policy
that points to the tools.jar is correct and declares the protocol (file in this case). For example, depending on where thejava.home
variable points to, you may need to remove the../
part in the path just like this (I had to):grant codebase "file:${java.home}/lib/tools.jar" { permission java.security.AllPermission; };
Starting from Java 1.4 the policy file needs to be encoded in UTF-8 without BOM. The EOL (CRLF vs LF) shouldn't really matter. Please see "Default Policy Implementation and Policy File Syntax" document from Oracle, under "Changes" section for more information (link not provided because I don't have enough reputation points to post more than 2 links, but I'm sure you'll be able to find that document).
Use an absolute path to the policy file when running the jstatd command, e.g.
jstatd -p 12345 -J-Djava.security.policy=/absolute-path-to/jstatd.all.policy
EDIT: The
-J
parameter may no longer be required or supported in Java 1.8 so this command would be instead:jstatd -p 12345 -Djava.security.policy=/absolute-path-to/jstatd.all.policy
(thanks @lisak for pointing this out)
Finally, once you pass this point you may find other problems (I did) and these posts pointed me in the right direction: Using VisualVM to monitor a remote JBoss instance and Remote Profiling of JBoss using VisualVM. Basically you may need to use the -p parameter to use a different port if 1099 is already in use and add some java options in the JBoss
run.conf
viaJAVA_OPTS
(assuming you are monitoring JBoss instance). All explained in more detail in the links provided.
EDIT: - Pointed dead link Using VisualVM to monitor a remote JBoss instance to another page with the same content.
I have the same problem and that what you should do:
- Make sure that
javac
is in your $PATH - Specify full (absolute) path to the policy file when running jstatd
jstatd -J-Djava.security.policy=/path/to/jstatd.all.policy
It helped for me.
A one liner using process substitution (though bashism):
jstatd -p 1099 -J-Djava.security.policy=<(echo 'grant codebase "file:${java.home}/../lib/tools.jar" {permission java.security.AllPermission;};')
Wrapped:
jstatd -p 1099 -J-Djava.security.policy=<(echo 'grant codebase "file:${java.home}/../lib/tools.jar" {permission java.security.AllPermission;};')
As of jdk1.8.0_92
, the java launcher option prefix -J
is still required.
Note:
The original problem is more likely due to the tilde ~
, in ~/jstatd.all.policy
, isn't expanded hence not understood by java, meanwhile either absolute path or using ${HOME}
instead should work.