简体   繁体   English

间接获取命令行参数

[英]Getting command-line arguments indirectly

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. 通过类加载器加载的类会利用这一点,因此它们无权访问程序的main方法。

I know I can get the JVM arguments via: 我知道我可以通过以下方式获取JVM参数:

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. 但是,阅读RuntimeMXBeanjavadoc似乎无法弄清楚如何获取其余参数。

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. 但是,这也不适用于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. 编辑:为澄清起见,我没有能力修改加载类文件的原始项目。

我对这种类型的问题不是很有经验,但是您是否不能为要加载的类创建一个实例字段以及一个存储主程序参数的字段,然后仅为实例字段分配参数的值?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM