2

I have a requirements whereby when the client connects to the server, the server has to find out if the client is running with -javaagent: or not ? Both server and client is written in java . Is there a way the server can get hold of java options that the client is running with ?

3 Answers3

1

On the client, you could use RuntimeMXBean to get the JVM arguments. I'm hoping the -javaagent parameter will also be exposed there.
See how-to-get-vm-arguments-from-inside-of-java-application for an example.

Community
  • 1
  • 1
KompjoeFriek
  • 3,572
  • 1
  • 22
  • 35
1

The server can find out by the client telling it, like anything else the server wants to know about the client that isn't implied by the connection (e.g. you know the remote address of a TCP client, there's no point in the client sending it over the connection). Sending the client's JVM arguments to the server is unadvisable tight coupling, however. If the server behaves differently based on the client's JVM arguments, then anytime the JVM arguments change the server will have to be updated to handle them. Instead, factor out the varying behavior into a flag that the client sends the server. For HTTP this could be a query param, for RMI a method param, for a roll-your-own protocol...well, you get to roll your own.

Steve McKay
  • 2,123
  • 17
  • 26
0

Use this API System.getProperty(PropertyName) to check the property name. It could use to find JVM arguments also. If its returns value then what you expect could be achieved.

Mohan Raj
  • 1,104
  • 9
  • 17