29

After spending half a day searching and trying, I'm finally giving up.

I have a java application of which I create a runnable jar (to include any other libs and just have a single jar file). With launch4j and the runnable jar I'm making an executable "MyApp.exe".

The executable ist working fine, but I want to pin it to my windows 7 taskbar. For now, I just have the taskbar entry "Close window".

After reading and implementing the following solutions with JNA

my Application displays it's "Application User Model ID" correctly in the gui (just for testing purpose).

BUT: my program is shown as "javaw.exe" in the Task Manager and I still can't pin it to the taskbar, even though I set the launch4j option "custom process name and XP style manifest".

Background information: I'm working with a windows 7 admin account and I don't want the app the require admin rights.

Anyways, if I start the app "as administrator" from the context menu and confirm the UAC message, I can now pin to the taskbar. BUT: even though I set the "Application User Model ID" properly, windows still wants to pin "javaw.exe", even though my program is now shown as "MyApp.exe" in the TaskManager.

I'm totaly confused. But I'm obviously not the only one, having these issues. => See the last comments to Gregory Pakosz answer in Using JNA to get/set application identifier

Final questions:

  1. Gregory Pakosz way with JNA to set the "Application User Model ID" ( https://stackoverflow.com/a/1928830/1128689 ) is working for me. But still, windows recognizes my app as an instance of "javaw.exe". What else do I have to do?
  2. Did maybe some windows or java update break something here?
  3. Do I really have to run my app with elevated user rights? I really don't want to...
  4. Are there some more options in launch4j which I have to set?
  5. Do I have to use a manifest file in launch4j?
Community
  • 1
  • 1
ToFi
  • 1,009
  • 13
  • 29
  • You might find some of the information you're looking for in this [thread](http://stackoverflow.com/questions/9330209/whats-the-best-way-to-start-java-applications-on-windows-7). Good luck! – Alexandre Mar 28 '12 at 15:20
  • You are missing one more step: an application Windows shortcut with *embedded* AppModelUserID. This can be created using a setup installer builder like [NSIS WinShell plugin](http://stackoverflow.com/questions/9330209/whats-the-best-way-to-start-java-applications-on-windows-7) and [InnoSetup](http://stackoverflow.com/questions/5438651/launch4j-nsis-and-duplicate-pinned-windows-7-taskbar-icons) – ee. Mar 29 '12 at 00:34
  • Another guide http://stackoverflow.com/questions/5646813/how-to-make-exe-file-for-izpack-installer-jar-file/5647255#5647255 and http://stackoverflow.com/questions/9342651/pinning-a-java-application-using-launch4j-to-the-windows-7-taskbar – ee. Mar 29 '12 at 00:42
  • 1
    @ee. thanks, but in the end, all these solutions come up with an application shortcut with embedded AppModelUserID. Which can only be created by an InstallTool. Unfortunately, I can't use an Installer because the App should be runnable without installation (e.g. on a usb drive)... – ToFi Apr 25 '12 at 14:36
  • @ToFi we have no choice but it is how it is designed to work with Windows 7's taskbar functionality as revealed in http://code.logos.com/blog/2009/12/displaying_a_splash_screen_with_c_part_v.html `Finally, your MSI that installs a desktop or Start menu shortcut for the application needs to set the System.AppUserModel.ID property on the installed shortcut, as detailed in the Windows 7 Taskbar support with the MsiShortcutProperty table blog post.` – ee. Apr 27 '12 at 01:19
  • @ToFi Just hope that someone can create a Windows 7 Shortcut creator library using Java like the non-free [JGoodies](http://www.strixcode.com/j7goodies/) library which has a [Shortcut](http://www.strixcode.com/j7goodies/api/index.html) class – ee. Apr 27 '12 at 01:44
  • Someone opened a feature request for native AppModelUserID support in launch4j: https://sourceforge.net/tracker/?func=detail&aid=3483933&group_id=95944&atid=613103 Help getting this feature in the next 3.1 release! – ToFi Dec 28 '12 at 11:58

4 Answers4

1

I got this working by creating an Exe from a runnable jar with the help of JSmooth .Pinned it to the taskbar, and ran it with no problems.

Hope this helps

Reg
  • 9,618
  • 6
  • 28
  • 46
1

No problem with winrun4j either, which is newer and easier to use than Jsmooth

Paul Taylor
  • 12,050
  • 34
  • 149
  • 295
1

The root cause: javaw is registered as a Host process (in Windows' registry). The shortcut behaviour is probably caused by following (source: Application User Model IDs (AppUserModelIDs))

Application-Defined and System-Defined AppUserModelIDs

Some applications do not declare an explicit AppUserModelID. They are optional. In that case, the system uses a series of heuristics to assign an internal AppUserModelID.

[...]

if the process was launched through a shortcut that contains launch arguments (usually the target content to host as the "application"), the system can determine identity and the application can be pinned and relaunched.

About the Host Process behaviour:

Registering an Application as a Host Process

An application can set the IsHostApp registry entry to cause that executable's process to be considered a host process by the taskbar. This affects its grouping and default Jump List entries.

Rekin
  • 8,723
  • 2
  • 22
  • 36
0

Are you looking for this, which I used in my application to show the running Java application on windows taskbar..

SystemTray systemTray = new SystemTray(composite, parent.getShell(), parent.getDisplay(), "My Application");
systemTray.makeSystemTray();
Kishore_2021
  • 604
  • 9
  • 33
  • Thanks, but unfortunately that's not what I'm looking for. With SystemTray you can display an icon in the Windows SystemTray (near your system clock). But I wanna be able to pin my java application to the Windows 7 Taskbar [like that](http://stackoverflow.com/questions/1834599/pinning-a-java-application-to-the-windows-7-taskbar) – ToFi Apr 25 '12 at 14:27
  • In the same way that JDK1.6 introduced the new SystemTray icon class/functionality, for this to work, Oracle would need to add classes to handle this type of functionality. So, to me it sounds like you would need to code your own solution just like people were doing with SystemTray before JDK 1.6 was released. Its unlikely, but it sounds like WinRun4j and JSmooth have done this? – djangofan Sep 24 '12 at 17:39