如何在java中从系统中运行jar文件名

时间:2021-10-19 15:59:50

I have a jar named helloDemo. I have double clicked on the jar file to run, assume it is running now. Now in another program I want to get all the jar file names and print them which are currently running or active in my system (windows7). Is there any way to do it ? I have goggled for it but no luck. Can anybody please help me on this ?

我有一个名为helloDemo的jar。我双击了要运行的jar文件,假设它现在正在运行。现在在另一个程序中,我想获取所有jar文件名并打印它们当前在我的系统中运行或活动(windows7)。有什么办法吗?我为此瞪眼但没有运气。有人可以帮帮我吗?

2 个解决方案

#1


You can list all Java processes on the local machine or a remote machine with using Java Virtual Machine Process Status Tool - jps:

您可以使用Java虚拟机进程状态工具列出本地计算机或远程计算机上的所有Java进程 - jps:

jps [options] [hostid]

jps [选项] [hostid]

  • options - list of options
  • 选项 - 选项列表

  • hostid - host identifier of the remote machine.
  • hostid - 远程机器的主机标识符。

For more information:

欲获得更多信息:

#2


I assume you have successfully created a runnable jar, and not a simple archive, (if you're not sure about that, this question might be helpful: How to make an executable jar file) and HelloDemo.java looks like the further code (or something more elaborate) to ensure it will run a long time.

我假设你已经成功创建了一个可运行的jar,而不是一个简单的存档,(如果你不确定,这个问题可能会有所帮助:如何制作一个可执行的jar文件)和HelloDemo.java看起来像是进一步的代码(或更精细的东西),以确保它会运行很长时间。

public class HelloDemo {
  public static void main(String[] args){
    while(true);
  }
}

Ok, this one runs a very long time ;P

好的,这个运行了很长时间; P

So, you're able to launch a bunch of java process, and now want to list them. Well, * is all you need:

所以,你可以启动一堆java进程,现在想要列出它们。那么,*就是你所需要的:

#1


You can list all Java processes on the local machine or a remote machine with using Java Virtual Machine Process Status Tool - jps:

您可以使用Java虚拟机进程状态工具列出本地计算机或远程计算机上的所有Java进程 - jps:

jps [options] [hostid]

jps [选项] [hostid]

  • options - list of options
  • 选项 - 选项列表

  • hostid - host identifier of the remote machine.
  • hostid - 远程机器的主机标识符。

For more information:

欲获得更多信息:

#2


I assume you have successfully created a runnable jar, and not a simple archive, (if you're not sure about that, this question might be helpful: How to make an executable jar file) and HelloDemo.java looks like the further code (or something more elaborate) to ensure it will run a long time.

我假设你已经成功创建了一个可运行的jar,而不是一个简单的存档,(如果你不确定,这个问题可能会有所帮助:如何制作一个可执行的jar文件)和HelloDemo.java看起来像是进一步的代码(或更精细的东西),以确保它会运行很长时间。

public class HelloDemo {
  public static void main(String[] args){
    while(true);
  }
}

Ok, this one runs a very long time ;P

好的,这个运行了很长时间; P

So, you're able to launch a bunch of java process, and now want to list them. Well, * is all you need:

所以,你可以启动一堆java进程,现在想要列出它们。那么,*就是你所需要的: