Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Java process name on Windows

Our Java Swing application is running on Windows and wrapped in an exe file using Launch4J.

We would like to customize our application process name and description (in Windows' task manager) as it is currently "javaw.exe" and "Java Platform SE binary" (which is confusing for our customers).

While older versions of Launch4J enabled to change this using <customProcName>, this option is now defunct as it is not working anymore as of Win7.

Is there any other (simple) workaround to customize our application process name and description?

For instance, changing javaw.exe executable filename seems like an approach (as we embed it in the wrapped exe file) but how then indicate to launch4j that the jvm file name changed?

Another option could be to create a launcher exe file: maybe an overkill?

Any ideas / hints are more than welcome; thanks!

like image 723
Tom Avatar asked May 24 '15 20:05

Tom


People also ask

How do I start a Java process in Windows?

Click on the Start button and then click on the Control Panel option. In the Control Panel Search enter Java Control Panel. Click on the Java icon to open the Java Control Panel.


2 Answers

If you're looking to roll your own solution, you're going to want to look at JNI and the Invocation API in particular JNI_CreateJavaVM() which is used to create a VM, find the main method GetStaticMethodID() and invoke it with CallStaticVoidMethod.

This is what the java.exe, javaw.exe and a variety of other native launchers do internally. Some examples include:

  • OpenJDK java.c
  • IntelliJ WinLauncher.cpp
  • WinRun4J VM.cpp

If you want don't want to integrate a native build system with your java build system, an approach is to build a static launcher.exe in advance, and treat it as a static binary blob. Then during your java build, modify the binary blob using java, to update the VERSIONINFO, icon and splash screen. An example of this approach can be seen in IntelliJ LauncherGeneratorMain.java

like image 76
user4978670 Avatar answered Oct 12 '22 04:10

user4978670


If you can afford it, JSmooth seems to do what you need. It's last released in 2007 though. A note about its license taken from the app itself:

The executable generated (the launchers created by JSmooth) are under the LGPL with a "runtime exception" similar to the gcc licence exception: It is not required that you distribute the source code with it, nor that you publish a notice mentionning jsmooth.

When using JSmooth, there is a section labeled "Skeleton" that allows you to select some pre-defined parameters. One of them is a "Windowed Wrapper" that is fit for GUI applications described as follows:

This skeleton wraps GUI applications.

  • No console I/O is displayed
  • If no Java VM is found, it is able to display a configurable URL (typically to a java download page).

Arguments can be passed to the application (either use the JSmooth default argument mechanism, or create a shortcut with arguments).

The important thing in this skeleton is to check the option "Launch java app in the exe process" which results in running the JVM in the same process as the wrapper exe. This means only the exe is shown in the Windows Task Manager, as opposed to both the exe and the java process.

The alternative is to write your own wrapper. See this Oracle guide for how to invoke the JVM from a native application.

like image 28
M A Avatar answered Oct 12 '22 03:10

M A