Any way to have Java Web Start automatically install shortcuts? - java

We're deploying a Web Start app that I and the other developers know how to install the shortcuts for (Control Panel -> Java on Windows, /Applications/Utilities/Java Preferences on OS X), but we have no reason to believe that end users know how to do this (or even know that it can be done).
Is there a way to either install the shortcuts automatically on first run, or (much preferably) ask the user if they'd like to install the shortcuts? I've been looking all over but the Sun/Oracle docs all say to go through the Java cache viewer, which I find completely ridiculous to ask of end users.

The JNLP specification allows for specifying that short cuts are to be created when the JNLP file is run.
Check the <jnlp><information><shortcut> tag.

The javaws command states:
Usage: javaws [control-options]
control-options include:
....
-import [import-options] <jnlp-file> import the application to the cache
import-options include:
....
-shortcut install shortcuts as if user allowed prompt
so you could probably do it through an invocation of javaws.

As of 1.6.0_18+, JWS offers the IntegrationService.
The IS can not only install/uninstall desktop shortcuts and menu items, but will report the success or failure of attempts to create/remove them.
Some minor points on standard use of shortcuts (through the JNLP file) using Windows and Linux. JWS will prompt the user only if the app. is sand-boxed. If the app. is trusted, it will go ahead and attempt to create the shortcut.
On Ubuntu Linux the menu items will fail silently, but the desk-top shortcut works. I have been meaning to investigate whether Ubuntu menu items will work better using the IS, by targeting the sub-menu to one of the standard sub-menus offered. If that is the case, menu items might be installed by the application targeting different menu structures on different OS'.

Related

How Java Control Panel on windows functions in conjunction with many different versions of Java installed on the machine?

I'm struggling with specifying which one of the many java installations on my Windows 7 machine would be used by the Internet Explorer for (1) running applete as well as (2) for Java web start.
For example, I am going to that Java-View tab in Java Control Panel, change the checkbox there, then make Java Console visible in the advanced tab and then find from the Console header that not always Java which is checked in the Java-View is actually executing applets in my browser.
In Java Control Panel Java-View along with the "User" tab, there is also a "System" tab.
One usually cannot change anything there, but what does that mean, and does it play any role?
In Java Control Panel Advanced tab you see "Default Java for browsers" checkboxes.
Why Microsoft Internet Explorer checkbox there is always checked and always grayed out?
Is this checkbox important or is it Java-View tab screen, which actually affects IE operations?
Also in jre/bin folder of each java instalation I see javacpl.exe file and can execute each of them, but only one of them, I guess, appears in actual computer Control Panel. How do you determine, which of them is really shown and can be executed through my computer Control Panel? Does it make sense to do anything with alternative javacpl.exe executables - will their execution affect my IE java-related functionality.
Basically, I'm in total confusion of how this mechanism works, and wwould very much appreciate if someone could give some clarification on at least some part of the above questions. And I'm mostly talking here about Java 1.6 and Java 1.7, I guess it would be even more difficult if we try to cover in this question also older java versions.
Thanks a lot for any help on this subject.
Regarding your first question
" which one of the many java installations on my Windows 7 machine would be used by the Internet Explorer for (1) running applete as well as (2) for Java web start."
This can be tested by making your applets contain Java 7 features like "Diamond Operator". Compile it by jdk 1.7 and then try to run in browser, if it runs then your browser is using 1.7 else 1.6.
Second ques -
"In Java Control Panel Java-View along with the "User" tab, there is also a "System" tab. One usually cannot change anything there, but what does that mean, and does it play any role?"
Answer- This is my guess that system tab will contain that option which is configured in JAVA_HOME environment variable OR it can that jdk which was installed more recently installed. Because offcourse default can be only one and not two.
Third question -
"In Java Control Panel Advanced tab you see "Default Java for browsers" checkboxes. Why Microsoft Internet Explorer checkbox there is always checked and always grayed out? Is this checkbox important or is it Java-View tab screen, which actually affects IE operations?"
Answer - The option is grayed out because the option is already chosen for you and you need not specify that.
Hope that helps.

Install and uninstall a java application in ms-windows

I have created a java application.
I also created another java application which install the first application.
The program runs perfectly.
However the program isn't displayed in control panel->programs.
I also want to create an uninstaller (let's say unintaller.bat). But i want to works like any other uninstaller. When someone goes to Control Panel->serach program->uninstall this program it will run the uninstaller.bat
In other words, the concept is how to declare the java application in windows...
Any idea???
Installing an application doesn't necessarily mean registering it with the operating system. For example, for a Mac, I can open an App without having it added to the Applications folder.
Same with Windows. Just because a new file can be added to the Start menu, it doesn't mean it was registered.
Use a Windows installer. There are tons that are open source, and even MS provides a free one: http://support.microsoft.com/kb/942288.
This will allow you to install an uninstall an application using standard tools. Yes. It can be called from a bat file.
Java open source installers: http://java-source.net/open-source/installer-generators

Pinning a Java executable (with launch4j) to the Windows 7 taskbar

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
Pinning a Java application to the Windows 7 taskbar
Using JNA to get/set application identifier
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:
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?
Did maybe some windows or java update break something here?
Do I really have to run my app with elevated user rights? I really don't want to...
Are there some more options in launch4j which I have to set?
Do I have to use a manifest file in launch4j?
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
No problem with winrun4j either, which is newer and easier to use than Jsmooth
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.
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();

How to launch an app with elevated privileges on Vista+ using Java / JNA to trigger UAC

I'd like to programmatically launch an application (a second JVM) from a Java app using JNA.
Please note that I can't :
add a Windows manifest to the JVM (minimal impact on the client)
use right click "runas administrator" (clicking "Allow" in the UAC dialog will be complicated enough)
I've seen other Questions with answers that states "use an exe" like Java: run as administrator but I was wondering if anybody tried this using JNA
To start an application with elevated privileges, you have to use ShellExecute and pass "runas" as the value of lpOperation parameter. This method does not require you to modify the JVM to add manifest to it. This behaves as if user right-clicked the application and selected Run as administrator command.
Note: on Windows XP, you should not use "runas" because it prompts for user credentials.

UAC and Java

Is it possible to ask for elevated permissions from within a Java Application? Suggestions I've seen seem to all be centered around running an external executable or setting up a manifest to request privileges on launch. These aren't available to, for instance, applets. Is there any way to request elevation from a running application?
UAC is not something that a running process can request (doesn't matter what language you are running in). You have to request elevation at launch time.
The way that most windows apps handle this (and make it look like they are requesting elevation) is to spawn an extra copy of themselves, requesting elevation, and passing sufficient command line arguments to the new process so that the appropriate dialog can be displayed.
This is why UAC elevation in a dialog is always initiated by a button click that opens a new dialog.
So, in the Java world, you just have to do exactly what everyone else has to do: launch your app again, requesting elevation. There are several ways to launch elevated, the 'run as' verb probably being the easiest.
Looks like Sun will have to handle that kind of situation in the JRE since there's no other way of doing elevated actions than by running an external process.
If JRE supported it, JVM would probably have to run a separate, elevated process for the java code requesting the elevation.
For now however, only the manifest or running an external application are the only solutions available as far as I know.
The question is, what do you need elevation for?
You have to use an external (native) application to do this. This post provides source code and a great explanation:
UAC Prompt From Java
You could use jna and do a ShellExec. For lpOperation use "runas" (this is not documented). Since you likely need the full path to the (current) JavaVM which is stored in the registrylook at registry access, part of JNA.
Goto the folder where java is installed.
open the properties of javaw.exe / java.exe and set "run as administator" option true.

Categories

Resources