Java applet: run native code from browser? - java

Is it still possible to start a 'native' application under windows via a java applet in a browser? IE "Click here to start notepad.exe" on a web page. The most recent reference I could find for this was dated 2002. Im wondering if this model / concept is no longer supported.

Yes, but the applet has to be signed.
Signed applets will prompt the user to give them permission. Once given, the applet has the same rights as any application running on the machine, including the ability to launch native apps (or link native libraries, which I've had to do in the past).

..Is it still possible to start a 'native' application under windows via a java applet in a browser?
Sure thing. As mentioned in other replies, a signed (and trusted) applet can use Runtime.exec(String) to launch a native application.
As of Java 1.6, it becomes simpler with the implementation of Dekstop.getDesktop.open(File), which will open the selected File with whatever application the OS has registered as a consumer for that file type.
As of Sun's Plugin2 architecture (1.6.0_10+ in a Sun/Oracle JRE) offers a more generic method for an (sand-boxed) applet embedded in a web page, using the JNLP API's BasicService. Here is my demo. of the BasicService

The portable way of doing this is to create a signed Applet.

Related

Java browser that support applet

Is there's any java embedded web browser(free) that support applet running ?
I don't mind if its use some native libraries.
Currently ,I already tried javafx web view and DJnativeswing and they dont detect java(doesn't support applet).
Most of the modern browsers (Chrome v42+, Firefox 64 for Windows, Microsoft Edge, etc) have dropped support for NPAPI which is required for applets to run. Oracle is recommending that developers switch over to Java Web Start instead of using applet as the technology is fading. If you still need to use applets (eg. for school programming projects) you may need to uninstall your current browser(s) and install a legacy browser that still includes NPAPI.
Browser do not support applets nativly. That's because applets need a java runtime environment and an browser adapter to display the content in the browser. But if you install a jre it always will install an plugin into you browser(s) if not already present.

Chrome packaged app with a Java applet

Is it possible for a Chrome packaged app to contain a Java applet?
I'm attempting to integrate QZ-Print / jZebra into a packaged app, however the applet does not appear and JavaScript receives an error of applet / can't read method of undefined when attempting to call a function.
No, you cannot use any (NPAPI) plugin in a Chrome app.
The documentation lists several Disabled Web Features. Flash and Non-sandboxed plugins are both listed, so they cannot be embedded in a Chrome app. Flash -as a (sandboxed) PPAPI plugin- could be embedded inside a <webview> tag, but Java is a non-sandboxed NPAPI plugin, so it cannot be used in a <webview> tag.
And you cannot use Java applets within a legacy packaged app either, because Java does not support Chrome extensions. You might have more luck if you try to embed the Java applet from a http(s) site.
Note that both Java applets and legacy packaged apps are deprecated and going to be removed from Chrome in the future (announcement for Java plugins, announcement for packaged apps), so you should try to look for alternatives such as native messaging.
It will be an ad-hoc solution, but you can set "always allow" manually in chrome://plugins

Can I remove any need for dialogs when running a Java applet in the browser?

I am running a Java applet in the browser. However, each browser displays a warning of
"This applet may not be trusted... etc."
and the user is allowed to click Run Anyway or Cancel. This is built in to the browsers / Java configuration. (If the user is running on a security level > Medium, the applet is simply blocked.)
Is there a way for me to sign the applet in such a way that no dialogs appear? Or will they still appear even if the applet is "trusted"?
No, you cannot.
It is no longer generally considered safe to run Java in the browser. The Java plugin has implemented a number of security measures that will display a spectrum of different security warnings depending on the user's current Java security level and the signed status of the applet, but no settings will disable the warnings entirely (short of settings which block the applet from loading at all). Additionally, some web browsers and operating systems have begun to apply their own, separate restrictions to Java applets. For instance, Google Chrome will display a warning bar before attempting to load the Java plugin, and Mac OS X does not install Java at all by default.
If you have any choice in the matter, avoid writing Java applets. Like many other older web technologies, like Shockwave and Quicktime, they are part of the past, not the future.

What is "java web start" used for?

I was reading about java web start from wiki. Can someone please tell me
What is it used for?
A practical application of it; to make its use clearer.
Do other languages like C++ / C# have
anything similar?
Thanks,
Roger
Java Web Start is kind of like a successor to applets - it allows Java programs to be run from your browser (though unlike applets, they don't run within the browser). For a practical example, see the TopCoder Arena.
http://www.topcoder.com/contest/arena/ContestAppletProd.jnlp
Here, Java Network Launching Protocol (JNLP) is the protocol that defines how a Web Start application should be run (analogous to HTML telling a browser how a page should be rendered).
See the Oracle tutorials:
Lesson: Web Start
Deploying a Java Web Start Application
Java Network Launch Protocol
Java Web Start software provides the
power to launch full-featured
applications with a single click.
Users can download and launch
applications, such as a complete
spreadsheet program or an Internet
chat client, without going through
lengthy installation procedures.
With Java Web Start software, users
can launch a Java application by
clicking a link in a web page. The
link points to a Java Network Launch
Protocol (JNLP) file, which instructs
Java Web Start software to download,
cache, and run the application.
I'm quoting the Java Tutorial lesson on WebStart
For those of you who work with .Net something like Java Webstart is ClickOnce technology.
Java Web Start is used to write sandboxed desktop applications similar to Java Applets. Like applets they can be launched from a web browser, but they run in their own window - not inside the browser.
It runs just like a normal application, but started from clicking a web page instead of having to download and run an installer. An advantage is that it's very easy to get people who are afraid of all the security warnings to try your application. Another advantage is that you don't need to keep the browser open while you run your application. You can even install a shortcut to your application onto the user's desktop so they don't need to touch the browser at all once they have run it the first time.
The .NET equivalent is Click Once.
What is it used for?
To roll out and keep updated an application to clients. Clients need "only" a Java Runtime installed. This may be more interesting to read.
Java webstart is used to deploy/install Java applications over the network.
The alternative is to send an application (MyApp.jar) to the users who will run that directly. But if it is out-of-date, they could have collisions when the application talks to the server (for example, or other such badness).
It also allows you to package all of the required libraries. This is a HUGE benefit.
http://java.sun.com/javase/technologies/desktop/javawebstart/index.jsp
As mentioned above, it's a technology to allow you to 'push' an always up to date Java app to users. It's not often used on a consumer level, but has some adoption in a corporate atmosphere.
It's best used in somewhat controlled environments, and is especially useful to push a specific version of client software to control a server.
Do other languages like C++ / C# have anything similar?
Yes. Microsoft provides something called ClickOnce that provides a web-based installer.
Today i am looking for the same example about the Java web start...
I thing this link will work for you,i have used as a beginner.
Click Here
As mention With Java Web Start software, users can launch a Java application by clicking a link in a web page. The link points to a Java Network Launch Protocol (JNLP) file, which instructs Java Web Start software to download, cache, and run the application.
We had a project, a plugin for Protégé, which is an ontology editor.
Installing the plugin isn't that hard, but to give the user a quick impression how the plugin worked, we supplied a Java Web Start application on our site. The page is still active, the plugin may have some rough edges, since it hasn't been updated for a while ... http://dac.icore.at/one/solutions.
I'm currently not aware of similar products for C/++/#.
Java web start is the 0-install solution in the java world.
An application built to use Java web start (JWS) will be available as a link in a web site. This site will have the .jnlp extension.
When a user clicks this link (and clicks the "execute" button of his browser) , the javaws.exe runtime will be launched. This executable will download the application and dependencies (libraries, images, and so on) and launch the application using the provided main-class of the .jnlp file).
An extensive reference of JNLP content can be found at http://lopica.sourceforge.net/ref.html
Examples of Java web start applications can be found at Swing sightings.
Notice that, depending upon the chosen configuration, these applciations can also be automatically installed in start menu.

Possible to launch JWS applet within browser instead of standalone?

Is it possible to embed an applet in HTML so that it will be displayed within the browser window yet launched through Java Web Start via a JNLP file instead of using the browser's Java plugin? If so, how is this done?
I've only been able to launch my applet in a standalone window, but disliking the user experience pop-ups create, I'd prefer that it be embedded in the browser window.
I'd like to use JWS instead of the plugin because I need to control my applet's maximum heap size, which I don't believe is possible with the browser plugin, at least not on Mac OS 10.5.
In-browser applets support JNLP deployment since 1.5 (or so). There's an example on how to do it here: http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html
You're still using the Java plugin then, of course. It may or may not work to set the heap size.

Categories

Resources