如何为我的 Java 应用程序提供唯一的进程名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1152356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:17:18  来源:igfitidea点击:

How can I give my Java application a unique process name?

javawindows

提问by Daniel Rikowski

I've noticed that when I start Netbeans it shows up in the task manager as netbeans.exeas all my own Java applications show up as java.exeor javaw.exe.

我注意到当我启动 Netbeans 时,它显示在任务管理器中,netbeans.exe就像我自己的所有 Java 应用程序都显示为java.exe或 一样javaw.exe

How can I change that so my process names shows up as myapp.exe?

我该如何更改,以便我的进程名称显示为myapp.exe

采纳答案by Luzifer42

The process name is the name of the JVM. So if you rename the jvm you have an other process name. There are some tools which can do that for you. For example Launch4J

进程名称是 JVM 的名称。因此,如果您重命名 jvm,您将获得另一个进程名称。有一些工具可以为您做到这一点。例如Launch4J

回答by skaffman

Netbeans and Eclipse both ship with an .exe file that in turns launches a JVM. The exe itaself probably does nothing after launching the VM. You see the NetBeans javaw.exe in the Task Manager also, I suspect.

Netbeans 和 Eclipse 都附带一个 .exe 文件,该文件依次启动 JVM。启动虚拟机后,exe 本身可能什么都不做。我怀疑您还会在任务管理器中看到 NetBeans javaw.exe。

So you'll need to write a native exe (using some windows tool) that does a similar thing.

因此,您需要编写一个执行类似操作的本机 exe(使用某些 Windows 工具)。

回答by Brian Agnew

Not easily. The easiest way (but not nice!) would be to simply copy the java.exe (only 68k on my system, so perhaps practical!)

不容易。最简单的方法(但不是很好!)是简单地复制 java.exe(我的系统上只有 68k,所以也许实用!)

If you're worried about identifying which java process is which (e.g. is one consuming memory/CPU etc.), use the standard tool jpsto identify the Java processes

如果您担心确定哪个 Java 进程是哪个(例如,一个消耗内存/CPU 等),请使用标准工具jps来识别 Java 进程

回答by Peter Smith

IMO the best option is to choose one of the many open source launchers. They all provide a nicer deployment container than java.exe and a batch file.

IMO 的最佳选择是选择众多开源启动器之一。它们都提供了比 java.exe 和批处理文件更好的部署容器。

I've compiled a list of them after a brief search on google (in no particular order and may not be exhaustive):

我在谷歌上进行了简短的搜索后整理了一份清单(没有特定的顺序,也可能不是详尽无遗):

(full disclosure: i work on winrun4j)

(完全披露:我在 winrun4j 上工作)

回答by Kevin Day

Just answered this a second ago here: Get JVM to grow memory demand as needed up to size of VM limit?

刚刚在这里回答了这个问题:Get JVM to increase memory demand as needed up to size of VM limit?

It's actually a loteasier than folks are saying (but you do have to have a c/c++ compiler handy).

它实际上比人们说的容易得多(但你必须手头有 ac/c++ 编译器)。

回答by jeffery.yuan

There are mainly 2 approaches: one is as already described: using tools like Launch4j, WinRun4J to create native Windows launchers.

主要有两种方法:一种是已经描述过的:使用 Launch4j、WinRun4J 等工具创建本地 Windows 启动器。

Another approach that seems better is to use Apache Procrun to wrap the java application as a Windows service. During the install service process, we can give the process an meaningful name such as OurApp.exe.

另一种看起来更好的方法是使用 Apache Procrun 将 java 应用程序包装为 Windows 服务。在安装服务过程中,我们可以给这个进程一个有意义的名字,比如OurApp.exe。

All we need do is rename prunsrv.exe to OurApp.exe and replace every occurrence of prunsrv.exe in our install|start|stop|uninstall service scripts to MyApp.exe.

我们需要做的就是将 prunsrv.exe 重命名为 OurApp.exe,并将我们的 install|start|stop|uninstall 服务脚本中出现的每个 prunsrv.exe 替换为 MyApp.exe。

See more from Using Apache Procrun to Rename Process Name of a Java Program in Windows

请参阅使用 Apache Procrun 重命名 Windows 中 Java 程序的进程名称的更多信息