I have a java agent that I want to be automatically enabled for any arbitrary java process running on the host.
I cannot rely on aliases or environment variables like
JVM_OPTS etc as I want any JVM process to pick the agent even if run directly as
/usr/bin/java -jar my-app.jar.
One (rather dirty) way of doing it is physically replacing
java binary with my custom bash script like this:
#!/bin/bash $(dirname "$0")/java.original "-javaagent:path/to/my-agent.jar" "$@"
It works, but that approach requires renaming the original
java binary file which I would like to avoid doing.
Question: Is there any better way how to achieve the same behavior without touching the
java binary? Are there any global Java specific config file where I could instruct Java to always run with the given agent?