I need to load a java agent without setting -javaagent. The reason why I need to do this is I have an exe that starts a JVM with command line args specified in a file. This exe filters -javaagent. How can I do this? I must load this agent via a command line argument, not via attachment later on.
Asked
Active
Viewed 1,038 times
1
-
Replace the .exe so it doesn't filter -javaagent. – Johannes Kuhn Apr 04 '22 at 22:12
-
4Try to set `JAVA_TOOL_OPTIONS` or `_JAVA_OPTIONS` environment variable. JVM should append the arguments from these variables, unless the executable also changes the environment. – apangin Apr 04 '22 at 22:18
-
2For reference, this is question no. 3 in a series of related questions by the same author. If you wish to follow his reasoning and learning process, see [no. 2](https://stackoverflow.com/a/71722089/1082681). I linked back to no. 1 there. They are all technically interesting, even though I am not convinced that the particular use case is legit. But hey, maybe he is a penetration tester... – kriegaex Apr 05 '22 at 00:10
1 Answers
2
"Try to set JAVA_TOOL_OPTIONS or _JAVA_OPTIONS environment variable. JVM should append the arguments from these variables, unless the executable also changes the environment. – apangin"
Thank you! Your answer worked. I set the environment variable temporarily in the command prompt. When the application was started from within the command prompt, the JVM accepted the JAVA_TOOL_OPTIONS temporary environment variable and loaded the -javaagent successfully.

Code Base
- 93
- 8