How to run a Swing application on a web page? - java

I have created a Swing application in Netbeans that is basically a chat system (between multiple clients and server using socket programming).
Now I wanted to run this application on a webpage. Is this possible without changing any code?

Now I wanted to run this application on a webpage. Is this possible without changing any code?
No. It would have to be a JApplet to be embedded in a web page, and applets have been effectively killed off. See Java Plugin support deprecated and Moving to a Plugin-Free Web.
On the other hand, a desktop application (based on a JFrame) can be launched from a link on a web page using Java Web Start.
Edit
Scrap that advice regarding JWS, apparently it too is being deprecated as of Java 9.

Related

Java GUI unable to automatically run on website

I have a Java program that runs a GUI that receives required information from the user/displays information. There is a button in the GUI that generates a Proposal in the form of a PDF that I wish the user to be able to download. I am having trouble having the GUI automatically run when the web page is opened, instead it just displays the icon of the JNLP file being referenced within the HTML.
Java Web Start does not run a GUI within a web page. Java Web Start is a technology for downloading and launching a local Java app on a JVM already present on the user’s machine.
Java Web Start has been phased out by Oracle, as Oracle no longer expects user machines to have a JVM pre-installed. See Oracle white paper, Java Client Roadmap Update.
OpenWebStart is an alternative open-source implementation of Java Web Start technology.
If you want to build a web app GUI using pure Java without having to learn HTML, JavaScript, DOM, WebSockets, etc., I suggest Vaadin Flow.

How to embed jetty and webkit like Electron framework does?

We have distributed web application and front-end part of this application should be standalone desktop application and have integration with desktop apps such as telephony. I saw Electron framework and apps (for instance Slack) built on top of it and it is pretty good.
Does Java world have such a tool for embedding of jetty/tomcat and webkit browser to built native desktop apps?
Similar questions:
Use embedded web browser (e.g. Chrome) as GUI toolkit for Java desktop applications?
Is it possible to create Desktop Application using Java backend & Web Technologies UI
Performance of WebView in JavaFX
Integrating JavaFX 2.0 WebView into a Swing Java SE 6 Application
Update:
See my test application on Java CEF: https://github.com/jreznot/cefc.
It uses Jetty/Swing/JavaCEF/Vaadin as HTML 5 Desktop Stack.
Final Update:
See my Electron+Java madness: https://github.com/jreznot/electron-java-app
It uses Electron with Java server side and Vaadin for application UI.
I recommend to use Electron instead of Java-Webkit bindings because it is mature framework and it has large community of JS developers.
I have search for similar solution in these last days and haven't found a totally fine solution.
These below is the more interesting partials solutions I have found.
Embed a browser (chromium) in java
I found two web site and is unclear what is the better solution:
jcef on github.com
build instructions
jcef on bitbucket.org
build instructions
I am not sure if these embedding solution will work well.
Please let me known if someone have found a quicker solution to embed web browser.
If you embed the browser into your code you have not trouble if the browser will update itself in the future and the user have your window container unless the standard browser window.
If you use an external browser you are sure on it well known behaviour but it can be change in the future and if this happens you have to update your application.
I choose to avoid embedded browser and reuse a standard external browser.
Embed http server
I like two solution I have found. All these solution can be use with minimal code change on your web application.
One thing is better you do is to make your web application a Maven application.
To do this in the past I have look at every library in web application class path and put in maven pom.xml dependency tree.
Spring-boot framework
Spring-boot is part of Spring framework.
It is a Spring projects: Spring-boot.
This project help a lot to start your web application.
Since you are developing a web application, you will add a spring-boot-
starter-web dependency in maven pom.xml
It standard embed server web is tomcat7/8 but you can change to Jetty8/9 or Undertow 1.1
Spark framework
This framework is a good alternative to Spring-boot. It is more concise and use Jetty as embedded web server.
I like Spring-boot because I am use to Spring configuration and use a mix of xml/annotation configuration and I like spring IoC. Using Spring-boot it easy to add other Spring constellation capability.
I hope that this can help you.
I think you can use wt. This is a system that takes a Qt based GUI application and rewrites the drawing mechanism from the usual desktop controls into html controls on a web page. IIRC its very transparent in that you only need to change a line or two of your original code. Qt is not java though, so I'm only pointing it out for completeness, its still pretty cool though.
But the simplest way would be to implement it using web technologies (eg HTML/JSP controls) so that it can be displayed as a web page easily, and then create a desktop app that uses the same html pages only wrapped as a 'executable'.
To create a desktop application you can either view the web page in an embedded browser in an application that exists solely to show the browser in a window, or you can use something like Microsoft's HTA system that presents web pages as desktop-style windows.
Credit goes to #gbjbaanb
Resource Link:
Is it possible to have a single code base for a desktop GUI and a
web application?
Run Jetty Web Server Within Your Application
Running a web application (WAR) with embedded jetty server

Java - Make a java program run on a webpage

Does anyone know how I can make a java program run on a webpage? I know many browsers now days do not support Java for security risk, but say I was using an older Java version like Java 6.
What would I have to do to get it to run on a webpage? Of course saying "Allow" or "Run Program" whenever the user clicks a button is alright. I cannot use Javascript for this.
Thank you
Another option, apart from Applets, is Java Web Start:
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.
If you are planning to do something very CPU consuming is better to use Java Web Start. But if you need some JavaScript And Java interaction it would be better to use the old Applets.
If you are worried about browsers blocking or not supporting Java Applets, then Java Web Start is again a better option.
The following links may be of interest to you:
Java Web Start (Jnlp) Hello World Example
Java SE 6: Migrating Applets to Java Web Start Applications
These things are called Applets. They are considered to be a bit old technology but they are still used at some places.
You can find a tutorial here

Can Java Web Start application work inside browser window?

This is the question: can JWS app occupy requin on web page or represent entire web page and/or access browser state parameters?
A Java Web Start application runs independently of the browser. If you want a Java app to interact with the hosting browser, you have to make it an applet.
See the last link in the applet info. page.
JNLP Support in the Next Generation Java Plug-In Technology (introduced in Java SE 6 update 10) goes into further details of the new abilities of applets.
I high-lit the version since it is a recent ability, and I got the impression you wanted to support older browser/JRE combos. from your earlier question.
That page expands..
The next-generation Java Plug-In technology (hereafter the "Java Plug-In") provides support for launching applets directly from JNLP files. Previously, only Java Web Start utilized JNLP files, for the purpose of launching Java applications. Now Java applets can be described using the same meta-descriptor.
Also note that launching an embedded applet using JWS does not solve any of the problems that inherently come with embedding a rich client GUI into the lighter HTML GUI.
Focus problems between HTML elements and the applet or applets. Sun never bothered to try and define what should happen, which resulted in either the applet or HTML getting focus, and that was it (as far as the keyboard went).
Then there is the matter of the PLAF of the applet which mimics, but never quite matches that of the elements used for HTML forms. Especially if they are styled, and that brings me to..
Applets do not respond to CSS! Perhaps intuitively obvious to applet developers, but no end of frustration to the site designer.
Typically there is at least one version of one browser that cannot load the simplest of applets correctly. My 'favorite' of all these type of bugs was a FF version that reloaded applets if the user scrolled 'up'. I could go on, and on, and on..

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.

Categories

Resources