Reputation: 11483
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.
Upvotes: 1
Views: 291
Reputation: 13
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?
Upvotes: 1