简体   繁体   English

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

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

I've noticed that when I start Netbeans it shows up in the task manager as netbeans.exe as all my own Java applications show up as java.exe or javaw.exe . 我注意到,当我启动Netbeans时,它会在任务管理器中显示为netbeans.exe因为我自己的所有Java应用程序都显示为java.exejavaw.exe

How can I change that so my process names shows up as myapp.exe ? 如何更改,以便我的进程名称显示为myapp.exe

The process name is the name of the JVM. 进程名称是JVM的名称。 So if you rename the jvm you have an other process name. 因此,如果重命名jvm,则还有其他进程名称。 There are some tools which can do that for you. 有一些工具可以帮到你。 For example Launch4J 例如Launch4J

IMO the best option is to choose one of the many open source launchers. IMO最好的选择是选择众多开源发射器中的一个。 They all provide a nicer deployment container than java.exe and a batch file. 它们都提供了比java.exe和批处理文件更好的部署容器。

I've compiled a list of them after a brief search on google (in no particular order and may not be exhaustive): 我在google上进行了简短的搜索后编制了一个列表(没有特别的顺序,可能不是详尽无遗的):

(full disclosure: i work on winrun4j) (完全披露:我在winrun4j上工作)

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 (eg is one consuming memory/CPU etc.), use the standard tool jps to identify the Java processes 如果您担心识别哪个java进程(例如消耗内存/ CPU等),请使用标准工具jps来识别Java进程

Netbeans and Eclipse both ship with an .exe file that in turns launches a JVM. Netbeans和Eclipse都附带一个.exe文件,该文件依次启动JVM。 The exe itaself probably does nothing after launching the VM. exe itaself在启动VM后可能什么都不做。 You see the NetBeans javaw.exe in the Task Manager also, I suspect. 我怀疑,您还可以在任务管理器中看到NetBeans javaw.exe。

So you'll need to write a native exe (using some windows tool) that does a similar thing. 因此,您需要编写一个执行类似操作的本机exe(使用一些Windows工具)。

Just answered this a second ago here: Get JVM to grow memory demand as needed up to size of VM limit? 刚刚在这里回答了这个问题: 获取JVM以根据需要增加内存需求以达到VM限制的大小?

It's actually a lot easier than folks are saying (but you do have to have ac/c++ compiler handy). 它实际上是一个容易比人都这么说(但你必须有C / C ++编译器方便)。

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. 另一种似乎更好的方法是使用Apache Procrun将Java应用程序包装为Windows服务。 During the install service process, we can give the process an meaningful name such as OurApp.exe. 在安装服务过程中,我们可以为进程提供一个有意义的名称,例如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,并将我们的安装|启动|停止|卸载服务脚本中每次出现的prunsrv.exe替换为MyApp.exe。

See more from Using Apache Procrun to Rename Process Name of a Java Program in Windows 有关详细信息,请参阅使用Apache Procrun重命名Windows中Java程序的进程名称

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

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