1

I am attempting to get the command-line arguments passed to a file indirectly. This is something that would be utilized by classes loaded through a class loader, so they do not have access to the main method of the program.

I know I can get the JVM arguments via:

RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = RuntimemxBean.getInputArguments();

However reading over the javadoc for RuntimeMXBean I cannot seem to figure out how to get the rest of the arguments.

I've also attempted to get the fun command-line execution via:

String arguments = System.getProperty("sun.java.command")

However that also does not work on every implementation of java. Is this even possible, and if so how?

Edit: For clarification, I do not have the ability to modify the original project loading the class files.

Rogue
  • 11,105
  • 5
  • 45
  • 71
  • Related: http://stackoverflow.com/questions/5061367/how-to-get-the-command-line-arguments-from-another-class-with-java and http://stackoverflow.com/questions/54686/how-to-get-a-list-of-current-open-windows-process-with-java – Flight Odyssey Nov 23 '13 at 01:21

1 Answers1

1

I'm not very experienced with this type of problem, but couldn't you create an instance field for the class you are loading and a field that stores the main program arguments, then just assign the instance field the value of the arguments?

0x277F
  • 13
  • 4
  • Or just pass a copy of the arguments to the class when you call the constructor, or just pass a copy to a method function. – steveha Nov 23 '13 at 01:15
  • I should have clarified further, but the whole idea is that the loaded classes are not provided the arguments (and I'm not the creator of the project loading them). I would consider creating a pull request for a change in some kind of accessor for this, but overall I was curious how to get this indirectly. – Rogue Nov 23 '13 at 01:17
  • @Rouge In that case, I don't have a clue what to do. Sorry! – 0x277F Nov 24 '13 at 22:32