1. <small id='u2S0V'></small><noframes id='u2S0V'>

      • <bdo id='u2S0V'></bdo><ul id='u2S0V'></ul>

        <i id='u2S0V'><tr id='u2S0V'><dt id='u2S0V'><q id='u2S0V'><span id='u2S0V'><b id='u2S0V'><form id='u2S0V'><ins id='u2S0V'></ins><ul id='u2S0V'></ul><sub id='u2S0V'></sub></form><legend id='u2S0V'></legend><bdo id='u2S0V'><pre id='u2S0V'><center id='u2S0V'></center></pre></bdo></b><th id='u2S0V'></th></span></q></dt></tr></i><div id='u2S0V'><tfoot id='u2S0V'></tfoot><dl id='u2S0V'><fieldset id='u2S0V'></fieldset></dl></div>
      1. <tfoot id='u2S0V'></tfoot><legend id='u2S0V'><style id='u2S0V'><dir id='u2S0V'><q id='u2S0V'></q></dir></style></legend>
      2. 是否可以获得用于在 java 中启动 jvm 的命令?

        时间:2023-08-24
        • <bdo id='ix6xK'></bdo><ul id='ix6xK'></ul>
          • <small id='ix6xK'></small><noframes id='ix6xK'>

            <legend id='ix6xK'><style id='ix6xK'><dir id='ix6xK'><q id='ix6xK'></q></dir></style></legend>

            1. <i id='ix6xK'><tr id='ix6xK'><dt id='ix6xK'><q id='ix6xK'><span id='ix6xK'><b id='ix6xK'><form id='ix6xK'><ins id='ix6xK'></ins><ul id='ix6xK'></ul><sub id='ix6xK'></sub></form><legend id='ix6xK'></legend><bdo id='ix6xK'><pre id='ix6xK'><center id='ix6xK'></center></pre></bdo></b><th id='ix6xK'></th></span></q></dt></tr></i><div id='ix6xK'><tfoot id='ix6xK'></tfoot><dl id='ix6xK'><fieldset id='ix6xK'></fieldset></dl></div>

                  <tbody id='ix6xK'></tbody>

                  <tfoot id='ix6xK'></tfoot>
                  本文介绍了是否可以获得用于在 java 中启动 jvm 的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道是否可以从代码中获取用于启动 java 程序的命令.

                  I would like to know if it is possible to get from code the command used to launch a java program.

                  例如如果我启动一个 java 程序:

                  E.g. if I launch a java program with:

                   java -cp lib1:lib2:... -jar mylib.jar com.foo.Bar
                  

                  我想得到确切的字符串(包括 jvm 参数).

                  I would like to get the exact string (jvm parameters included).

                  有可能吗?

                  评论赏金和问题

                  感谢大家的回复.不幸的是,我没有得到我最初想要的答案.我希望有一些可移植的解决方案可以从程序本身(包括类路径等)中获取完整的 java 命令.似乎没有可移植的解决方案,因为我使用的是 Linux,所以我使用 agodinhostLuigi R. Viggiano 的响应来解决我的问题.但是,我将赏金奖励给 rahulroc 以获得最完整(便携)的响应.对于其余的,所有人都赞成:)

                  Thank you all for your responses. Unfortunately, I did not get the answer I was initally looking for. I was hoping there was some portable solution to get the complete java command from within the program itself (including classpath etc.). As it seems there are no portable solution and since I am using Linux I am using the responses of agodinhost and Luigi R. Viggiano to solve my problem. However I give the bounty to rahulroc for the most complete (portable) response. For the rest an upvote for all :)

                  推荐答案

                  下面提到的代码应该显示所有JVM参数,传递给main方法的参数以及主类名.

                  The below mentioned code should show all JVM parameters, arguments passed to the main method as well as the main class name.

                  import java.lang.management.ManagementFactory;
                  import java.lang.management.RuntimeMXBean;
                  
                  import java.util.List;
                  
                  public static void main(String[] args) {
                    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
                    List<String> jvmArgs = bean.getInputArguments();
                  
                    for (int i = 0; i < jvmArgs.size(); i++) {
                      System.out.println( jvmArgs.get( i ) );
                    }
                    System.out.println(" -classpath " + System.getProperty("java.class.path"));
                    // print the non-JVM command line arguments
                    // print name of the main class with its arguments, like org.ClassName param1 param2
                    System.out.println(" " + System.getProperty("sun.java.command"));
                  }
                  

                  的 javadoc获取输入参数

                  返回传递给 Java 虚拟机的输入参数不包括 main 方法的参数.该方法返回如果没有 Java 虚拟的输入参数,则为空列表机器.

                  Returns the input arguments passed to the Java virtual machine which does not include the arguments to the main method. This method returns an empty list if there is no input argument to the Java virtual machine.

                  一些 Java 虚拟机实现可能需要输入参数来自多个不同的来源:例如,从启动 Java 虚拟机的应用程序,例如'java' 命令、环境变量、配置文件等

                  Some Java virtual machine implementations may take input arguments from multiple different sources: for examples, arguments passed from the application that launches the Java virtual machine such as the 'java' command, environment variables, configuration files, etc.

                  通常,并非java"命令的所有命令行选项都是传递给 Java 虚拟机.因此,返回的输入参数可能不包括所有命令行选项.

                  Typically, not all command-line options to the 'java' command are passed to the Java virtual machine. Thus, the returned input arguments may not include all command-line options.

                  你也可以看看:jps

                  这是一个 Java 程序,能够为所有用户获取完整的命令行Java进程,包括主类和JVM的全类名选项.

                  It's a Java program that is able to get the full command line for all Java processes, including full class name of main class and JVM options.

                  你可以找到一个很好的总结各种JVM 工具,包括Java 应用程序启动器 链接到:

                  You can find a good summary of various JVM tools, including Java Application Launcher links to :

                  • ManagementFactory.getRuntimeMXBean() - 返回 Java 虚拟机运行时系统的托管 bean.
                  • getInputArguments() javadoc
                  • 确定JVM是否在调试模式

                  这篇关于是否可以获得用于在 java 中启动 jvm 的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:java.exe、javaw.exe和jvm.dll的区别 下一篇:JavaFX 停止在 WebView 中打开 URL - 改为在浏览器中打开

                  相关文章

                    <bdo id='zm6eN'></bdo><ul id='zm6eN'></ul>

                  <small id='zm6eN'></small><noframes id='zm6eN'>

                • <legend id='zm6eN'><style id='zm6eN'><dir id='zm6eN'><q id='zm6eN'></q></dir></style></legend>
                  <i id='zm6eN'><tr id='zm6eN'><dt id='zm6eN'><q id='zm6eN'><span id='zm6eN'><b id='zm6eN'><form id='zm6eN'><ins id='zm6eN'></ins><ul id='zm6eN'></ul><sub id='zm6eN'></sub></form><legend id='zm6eN'></legend><bdo id='zm6eN'><pre id='zm6eN'><center id='zm6eN'></center></pre></bdo></b><th id='zm6eN'></th></span></q></dt></tr></i><div id='zm6eN'><tfoot id='zm6eN'></tfoot><dl id='zm6eN'><fieldset id='zm6eN'></fieldset></dl></div>
                  <tfoot id='zm6eN'></tfoot>