0

Is there any way where I can find out which Java options are being used by a Java application inside JVM (e.g. the ones passed through the command line)?

I want to find it on the fly when the application is running, but from outside outside the application.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
raj_arni
  • 959
  • 2
  • 15
  • 29
  • 3
    Is [this](http://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application) what you are looking for? – NullUserException Nov 16 '11 at 18:17

4 Answers4

1
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
    System.out.format("%s=%s%n", envName, env.get(envName));
}
Emmanuel Sys
  • 817
  • 6
  • 12
0

You can use JMX:

final JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(connectorAddress));
final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();
final ObjectName commandLine = new ObjectName("java.lang:type=Runtime");
final List<Attribute> arguments = mBeanServerConnection.getAttributes(commandLine, new String[] {"InputArguments"}).asList();
String[] inputArguments = (String[]) arguments.get(0).getValue();
System.out.println(Arrays.asList(inputArguments));
connector.close();

To get the JMX connection, you might find my answer to " JMX client accessible locally only " helpful.

Community
  • 1
  • 1
laz
  • 28,320
  • 5
  • 53
  • 50
0

Use JMX. It allows to get options, properties, etc. from inside as well as outside of application.

jmx

szhem
  • 4,672
  • 2
  • 18
  • 30
-1

I believe that Java does not support the "INTERCEPTING" of method arguments, method args are not logged or intercepted in the JVM .

However, you can easily print out the args sent to a running class using the System.env example in the other answer on this thread .

HOWEVER, if you have control over the actual applications source code, you can follow the directions here : How do I intercept a method invocation with standard java features (no AspectJ etc)?

This will allow you to log and intercept the args being sent to the main method.

Community
  • 1
  • 1
jayunit100
  • 17,388
  • 22
  • 92
  • 167
  • This is not what the question is asking, the poster wants the JVM args, not the args of any particular method. – jli Nov 16 '11 at 18:26