找到你要的答案

Q:how to get running jar file name from system in java

Q:如何获得运行JAR文件名从系统java

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文件名和打印他们正在运行或在我的系统(Windows7)。有什么办法吗?我已经为它但没有运气。有谁能帮我吗?

answer1: 回答1:

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

jps [options] [hostid]

  • options - list of options
  • hostid - host identifier of the remote machine.

For more information:

你可以列出所有的java程序在本地计算机或远程计算机使用java虚拟机进程状态工具JPS:

JPS [选项] [服务器]

  • options - list of options
  • hostid - host identifier of the remote machine.

更多信息:

answer2: 回答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.

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

Ok, this one runs a very long time ;P

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

我假设你已经成功地创建了一个Runnable JAR,并不是一个简单的档案,(如果你不确定,这个问题可能会有所帮助:如何使一个可执行jar文件)和hellodemo.java看起来进一步代码(或更复杂的)以确保它能跑很长一段时间。

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

好的,这个时间很长;P

所以,你可以发射一束java程序,现在要列出来。嗯,StackOverflow是所有你需要的:

java  windows  jar