Javafx in webpage? [duplicate] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have done some research on JavaFX over the last year, and even built some basic desktop apps with it.
It's described as being used to create RIAs (Rich Internet Application).
http://en.wikipedia.org/wiki/Javafx
But can it really be deployed by a web browser? I have only deployed it via an executable JAR file.
How easy is it to deploy via web browser? Does it work? Does anyone have experience with this?
http://docs.oracle.com/javafx/2/deployment/deployment_toolkit.htm

Update for the March 2018 Java Client Roadmap
I encourage readers interested in this question to review the following Oracle Whitepaper:
Java Client Roadmap Update
The above paper outlines the official Oracle position on related technologies (JavaFX/Swing/AWT/Applets/WebStart), the dates until which it intends to support those technologies and which of those technologies it intends to transition to open source development projects separate from the JDK and JRE.
Update for Java 9, Oct 2017
According to the Java 9 release notes:
Java Applet and WebStart functionality, including the Applet API, The Java plug-in, the Java Applet Viewer, JNLP and Java Web Start including the javaws tool are all deprecated in JDK 9 and will be removed in a future release.
So, for Java 9+, deployment of JavaFX in a browser using a Java plug-in will only be possible using deprecated technology. Oracle notes in another part of the Java 9 release notes:
Deprecates the Java Plug-in and associated applet technologies in Oracle's JDK 9 builds. While still available in JDK 9, these technologies will be considered for removal from the Oracle JDK and JRE in a future release. Applets and JavaFX applications embedded in a web page require the Java Plug-in to run. Consider rewriting these types of applications as Java Web Start or self-contained applications.
Note: Java Web Start isn't really an alternative as that is also deprecated (anyway, it's different from an application embedded and rendered within a browser page). Also note for those who wish to use Web Start, even though it has now been removed from Oracle JDK 11+, it is available as open source, info on this is at OpenWebStart.
As an alternative which offers similar functionality, consider something like jpro, which deploys JavaFX applications in a browser without a Java plugin (jpro is currently only in closed beta, so it is not a viable solution as of October 2017, but maybe someday in the future...).
For now, I would recommend that the best way to deploy JavaFX applications is as self-contained applications, running outside a browser.
Previous answer for Java 7 and 8
JavaFx - can it really be deployed in a browser?
Yes, JavaFX applications can be deployed so that they run inside a web browser hosted html web page.
The technology which allows this to occur is the Java Plugin. This plugin is currently a NPAPI based browser plugin solution. The Java Plugin is shipped with the Oracle Java 7 Runtime Standard Environment.
Not all browsers are supported, only those listed on the JavaFX Supported Configurations page.
How easy is it to deploy via web browser?
The easiest way to deploy a JavaFX project in a web browser is:
Create a new JavaFX project in NetBeans.
Develop a simple HelloWorld App.
Follow the instructions for Deploying your first JavaFX Application.
This is not difficult (in my opinion).
Alternatively, follow instructions on the detailed reference for Deploying JavaFX Applications (or use 3rd party tools). For many projects, using a tool other than the NetBeans IDE to perform packaging is a better approach. However, it is generally easier to let the NetBeans IDE handle deployment packaging tasks for you.
What follows is not related to answering the original question, but provides some opinions and information requested in comments on this answer.
Some Advice
There are pitfalls to deploying Java in a browser. I encourage you to do your own Google research on the subject.
In my mind, based upon the current JavaFX 2.x deployment model, for most application types that require a browser as the primary runtime container, using JavaFX is not an appropriate solution.
Examine the deployment and runtime requirements for your application. Based on your requirements, and knowledge of the JavaFX browser based execution model, decide if a browser based deployment using JavaFX technology is the correct mechanism for your application.
A couple of potential difficulties for browser embedded JavaFX applications
Some important browsers (e.g. Internet Explorer 10, iOS Safari and soon Desktop Chrome) don't permit execution of plugins using the NPAPI currently used by the Java browser plugin => some of your target users may be unable to use your application.
With a browser embedded application, you don't have complete control over the runtime on which your application executes (browser + Java runtime + plugin interface) => an application which was working when first installed may stop functioning as expected after an update to these runtime components.
Deployment Alternatives
If a browser based deployment model is not appropriate for your application, there are other ways to deploy JavaFX applications (e.g. WebStart, stand-alone jars and self-contained applications).

JavaFX - can it really be deployed in a browser?
No, not any more.
The answer used to be yes, as given in this answer, although even in 2013 when that was written the writing was on the wall. However, here in 2016 the answer is no, it cannot. Modern browsers essentially don't support NPAPI any longer (Firefox does for Java, but only until the end of the year), and NPAPI is required for the Java plugin.

As of 2016 you can use jpro without any browser plugin. And it even runs on mobiles.
Edit 1: The project is free for non-commercial or open source projects. A "hello world" can be found here

I found solution by chance here.
what was missing in my web project.
I must add this to web.xml file :
<mime-mapping>
<extension>jnlp</extension>
<mime-type>application/x-java-jnlp-file</mime-type>
</mime-mapping>

Related

Running a Java Program from a Browser without Plugins

Some weeks ago I wrote a little Java program showing a real time plot chart (i.e. records with tracking of current time), with a modest 25 kbps streaming rate, 20fps framing rate, and no relevant user interaction. Thinking on its eventual deployment as a Mobile App, a Web Server chart or simply as a PC as a program, being Java a perfect selection for me.
Before starting now the Web version of this program, i started to investigate and according the 2016 Oracle White Paper Migrating from Java Applets to Plugin Free Java Technologies:
The deprecated plugin technology will be completely removed from the
Oracle Java Development Kit (JDK) and Java Runtime Environment (JRE) in a
future Java release (TBD). Java Web Start applications do not rely on a
browser plugin and will not be affected by these changes.
And according 2019 OpenWebStart:
Java Web Start (JWS) was deprecated in Java 9, and starting with Java
11, Oracle removed JWS from their JDK distributions
And then I get lost.
Hence, which is the way to go with a Java program like this? Which is the proper sustainable Java way to do this (and not subject to something like what happened to Java Web Start)?.
Or should I simply move to another way to do it, now that the program is in its infancy, considering I am not precisely a fan of Phyton, considering PHP is not precisely the way for programming these kind of numerical things, and considering I am not so willing to give Microsoft technologies a chance?
It is not a problem for me to adapt and rewrite my current code if necessary, but possibly not doing this every 5 years.
Which article would you recommend me to get back to the proper path?
Thanks in advance.
The easiest and highest-performance option is TeaVM, a transpiler that converts Java classes into JavaScript. Your code then runs in the browser natively without any plugin.
Read an introductory article here: https://blogs.oracle.com/javamagazine/java-in-the-browser-with-teavm
TeaVM's main site is here: http://teavm.org/
Thinking on its eventual deployment as a Mobile App, a Web Server
chart or simply as a PC as a program, being Java a perfect selection
for me.
(..)
Hence, which is the way to go with a Java program like this? Which is
the proper sustainable Java way to do this (and not subject to
something like what happened to Java Web Start)?
Two lines of Java
What happened is that our old friend, the Java Standard Edition, split into two lines:
Oracle Java SE ("commercial Java"): needs paid license for commercial use for releases since April 16th, 2019
OpenJDK ("open source Java"): open source (GPLv2 with linking exception), does not contain Oracle's Java Web Start implementation
The Oracle Java SE version keeps Java Web Start and Java FX available and supported only for Java SE 8. Newer Java versions, esp. Java SE 11 do not carry these anymore.
It is not a complete client / desktop technology removal, because Oracle, according to the Java Client Roadmap Update 2018, continues to support AWT and Swing for at least 5 more years on both Java SE 8 and Java SE 11.
You can continue deployment via Java Web Start
Open source Java got a decent implementation of Java Web Start, which is free and available for Java SE 8 and newer Java versions like Java SE 11.
This is Karakun's OpenWebStart based on Red Hat's IcedTea-Web, now beyond version 1.0, which you already found.
Continued support is not guaranteed but seems likely. So you might continue on this track.
Or you might deploy via an app store
Oracle's explanation for dropping Java Web Start was, that they want to change the deployment model to applications with bundled runtime:
As client application development continues to shift from the old
“plugin” world to modern deployment, the need for a standalone Java
Runtime Environment (JRE) that is installed centrally, separately from
Java applications has diminished. Using the ‘jlink’ tool introduced
with JDK 9 will make it even easier for application developers to
package and deploy dedicated runtimes rather than relying on a
pre-installed system JRE.
(Source: Faster and Easier Use and Redistribution of Java SE)
Deployment, according to Oracle, would occur via some app store like the iTunes Store:
No doubt this was true, but the OSes have shifted hard and fast away
from this model. The "app store" model is now it. macOS has been
ratcheting this down hard for several years now. MSFT -- even in the
enterprise market -- has signaled this direction as well. For sure we
need to find options to support the legacy, but the future here is limited.
(Source: OpenJDK discussion mailing list)
Note that Java Start Web Start handled the updating of available new versions of applications on the client machines, and so do typical app stores.
Of course you can serve a version of your app with bundled runtime on your web site, but then you usually have to implement some mechanism to handle updates of your application on the machines of your users yourself.
What to choose?
It is true that the separate JRE installation has disadvantages, e.g. I changed my JRE recently and suddenly the IDE for Java did not work anymore. :-)
Moving deployment from a web site you control to an app store controled by the OS vendor or mighty players like Valve, has its own challenges. E.g. access restrictions, fees, release delays because of the review process, or they might not like your app for some reason and will not publish it.
Then adoption: Personally I have seen private use of app stores mostly on mobile devices and macs, but no use in companies yet. This might be a factor in your decision which road to pursue.
I've missed the Java on browser too. Because of curiosity I just developed an "JVM-Server", which precompiles the Java-Classes to native JavaScript and serves them to a WebBrowser.
Look here is a Hello World example application which is running on Browser:
https://github.com/neo-expert/jsjvm_helloworld
There is also a Library which implements WebGL bindings. In the above Example is a WebGL demo included, where a 3D cube will be rendered. The code is written in pure Java.
Is it a swing app? Will have to map that to a web (html) app to make it work on a browser nowadays.
You cannot run any of those programs from a browser directly.
Java used to java applets and java web start - where the browser helped you install a java app on local system but user had to seperately have installed JRE (Java run time) to run it locally.
Now all we have are web apps. basically apps that might have a a session, login, authenticaiton and authorition but in the end the app outputs HTML, Javascript, images and text data (JSON. XML etc) that is rendered on the web page.
Look at J2EE. I'm a java fan. but it takes longer to develop, but i think it runs better. Especially with a good framework like Spring Boot (it includes MVC see https://dzone.com/articles/7-best-java-frameworks-for-2016)
But learning curve is there. Buy a book or do a course online like udemy or similar.youtube has free videos. but not sure of the order/ quality.
If you choose php - many free and cheap servers like x10hosting to start with and learning curve is less too. Good framework - packages like drupal and wordpress.
On the browser HTML, Javacript run. There are frameworks for this too. Like gogole's angular https://angular.io/ this too needs a book/seperate study. Old days we used to use simple Javascript ...
For mobiles - sometimes can get away with using a URL OR there are frameworks that wrap a web page in an 'app' for android, iphone etc OR make a native app - but then will have different code bases.
I know someone who used a game engine to make a mostly single code base (some classes are specific to each platform like android, iphone) but used to render business graphs and a few interaction use cases (about 40). He used https://libgdx.badlogicgames.com/
As your research already revealed, Java is not a relevant web frontend technology anymore. Prefer Javascript and CSS for browser frontends, instead. Feed the frontend code with data served by Java backend services. The Java Servlet Specification is still the base for server-side Java. Many frameworks (like Spring or Jersey, to name a few) are build on top of it. Either chose one of these frameworks, or - for really simple use-cases - build an application only with plain servlets. Any servlet needs to be deployed in a servlet container (e.g. Apache Tomcat).
Your Java code needs probably some refactoring in order to provide an API for the web. As you are asking for near-realtime communication, you should have a look at the WebSockets standard which is designed for bidirectional and fast client-server-communication on the Internet and supported by all modern browsers (nice intro explaining the difference to WebRTC and arguing why WebSockets are often the better choice). To plot your data in a browser with Javascript and SVG, have a look on the D3.js library. A quick search brings you to demos like this one: D3 Real Time Chart. Also, there are other libraries that are built on top of D3, for example plotly.js.
Summary:
Java is fine for web backend services.
Your code needs refactoring to serve a backend API, preferably WebSockets. (introduction on how to start in Java at https://www.baeldung.com/java-websockets)
Get familiar with a Javascript browser plot library, such as D3.js.

How do I upgrade to jlink (JDK 9+) from Java Web Start (JDK 8) for an auto-updating application?

Java 8 and prior versions have Java Web Start, which auto-updates the application when we change it. Oracle has recommended that users migrate to jlink, as that is the new Oracle technology. So far, this sounds good. This comes with a host of benefits:
Native code on Windows, Mac and Linux
Modularization of the code (although Proguard does this as well)
The use of new, supported technology.
The problem: I can't find the canonical Java solution to auto-update with jlink.
One would think that Java Web Start could continue to be used, especially if one casually reads this document. Notice the fact that Java Web Start continues to be prominently listed. But there's a fly in the ointment: Oracle is deprecating Java Web Start. It's slated for removal in JDK 11. So, what's the official path forward. Failing that, is there a standard way that people proceed?
For the purposes of this question the following are out of scope:
Paying huge amounts of money yearly to someone with an feature-packed enterprise solution. The application to be distributed is already packaged into a single jar that is smaller than 50MB.
Forcing users to run an InstallShield style app to reinstall the new version, and then manually uninstall the old version every time an update is pushed. That's sooo 1990's.
Porting the entire app to be a webapp, rewriting the UI and client side logic to fit in a browser and dealing with all the incompatibilities that entails. The authors of the application worked on GWT and know exactly what web browsers are capable of. Unfortunately, they also know the level of effort required.
Allowing users to continue to run old versions of the application. That, too, is sooo 1980's. Modern apps update quickly, and supporting every version of the application ever released is not tenable. That's what my father's COBOL application had to deal with, and he didn't enjoy it. I'm hoping technology has progressed.
Continuing to use Java Web Start. Until/unless Oracle changes its mind, Java Web Start is a doomed technology.
In May 2019 commented to watch the OpenWebStart project.
Now (October 2019) it is time to give OpenWebStart serious consideration. While not yet feature complete, a alpha beta release of OpenWebStart is now available for download under a "GPL with Classpath exception" license.
The OpenWebStart Technical Details page states:
OpenWebStart is based on Iced-Tea-Web and the JNLP-specification defined in JSR-56. It will implement the most commonly used features of Java Web Start and it will be able to handle any typical JWS-based application. We plan to support all future versions of Java, starting with Java 11. In addition to Java 11, the first release of OpenWebStart will also support Java 8.
The page goes on to state that OpenWebStart will support interactive installers with auto-update, and non-interactive installers. Some JNLP features will be supported, and it will include a replacement for the Java Control Panel. A more comprehensive list of planned features1 and their implementation status is provided in the feature table.
1 - If you have a requirement that is not on their feature list (e.g. jlink support), you could contact the OpenWebStart team, and offer a suitable incentive (e.g. money to pay developers) to implement the feature for you. They also offer commercial versions of the software for paying customers.
Disclaimer: I have no connection with the OpenWebStart project, the company (Karakun) or the project sponsors. This is not a recommendation.
I had a similar problem in a past project. We needed to migrate from Webstart to another technology.
The first approach was to install IcedTea. It is directly bundled with the AdoptOpenJDK Project.
But as far as I understood the problem, Java wasn't meant to be installed on the Client side like this anymore and we didn't want problems with all of our customers.
Our solution was then building an own specific Executable, which connects to the server, ask for enviroment settings from the server side, and then download and extracts the JLink Java. So we could use the old technologies and just wrapped it in an Executable.
Last thing done then was redirecting to the download location of the Executable when calling the jnlp-URL.
Do you use maven?
I've resolved my similar problem with maven (I need to update an EAR).
My main app (the ear package) has a pom.xml with listed the dependencies and repositories.
The dependencies have the <version> tag with a range (documentation) as in this example
<version>[1.0.0,)</version>
That means : get version 1.0.0 or newer of the dependency. (You can put also an upper bound to the version, [1.0.0, 2.0.0) so if you develope a new version, it is not used in old app)
In the repository section I added my personal repository.
Now, in the remote machine I need only to rebuild my ear package with maven : the compiler download the newer version of my jar and put it together.
You need a system to check if there are newer dependencies version and warn the user to update the app and also lock its work (you can't work if you don't update). Maybe you need a little app to make users do the rebuild process easily. It's 1990's but a lot of desktop-app works in this way
PRO
This schema can be used in a lot of different projects.
CONTRO
You need to build the app in the remote machine, so the client must have a JDK and access to your repository (like artifactory);
You must write code in different jars and add them like dependencies in the main archive.
You must change JAR version each time and publish on the repository (this could be a good practice)

How to run existing JAVA Web start application in java 10 or later java 11

My application is developed in java Swings which is 20 years old. For this huge application we are migrating the same on JAVA 10 now and will migrate the same on java 11 or upcoming versions. This application is working fine with java Webstart and as per the java 11 features, java Web Start application will not be supported in java 11 and other coming versions.
Please let me know the best way to run my application on java 10 with out webstart.
There is OpenWebStart start project. It says:
we decided to create OpenWebStart, an open source reimplementation of
the Java Web Start technology. Our replacement will provide the most
commonly used features of Java Web Start and the JNLP standard, so
that your customers can continue using applications based on Java Web
Start and JNLP without any change.
At the moment the project is alpha phase. Download is available. Beta should be available by the end of the year:
Our goal is to have beta tests and a release candidate ready in
Q3/2019
One solution might be the WebStart replacement that Karakun is currently working on: https://dev.karakun.com/webstart/
Currently it is not clear when and how this will come since it is based on a kind of crowd-founding but since everyone can get involved (even with low cost) this is a very good possibility.
Since this is a duplicate of Applet/JNLP on Java 11 migration I just copied my answer
Use Getdown which is a system for deploying Java applications to end-user computers, as well as keeping those applications up to date.
It was designed as a replacement for Java Web Start due to limitations in Java Web Start's.
You can read more on https://github.com/threerings/getdown
You will have to find an alternative technology to JWS/JNLP to run your system, as JWS/JNLP will no longer be available.
I don't have a clear cut alternative, the few companies still using JWS tend to be working to develop their own replacements for internal use.
I know this may not be what you want to hear (that there is no out of the box replacement available) but that's the way it is. Project I'm working on is in a similar conundrum, we also have several JWS components that will need to be reworked in the near future.

Are applets dead?

A long time ago I made an applet, when I tried to a open it few days ago in website and it says that there is a security problem and it can not open it.
I Googled it and saw that I need to register it.
I tried to register it but nothing helped.
Can you explain what could make this problem?
The applet is fine and working when I run it from eclipse.
With recent updates to Java, security is much more strict. Your applet needs to be running the same java version and have a certificate. It's a very strict system...I can't open many java applets myself.
To make it run as an exception, copy the URL that the applet is on. Then open up your Java Control Panel, go to the Security Tab, and at the bottom hit Edit Site List at the bottom. From there, hit Add and paste in your link.
That'll allow it to run as an exception.
tl;dr
Java Applets are gone. You can modify your applet to run as a local app instead.
Today you can build local GUI apps in Java using your choice of three frameworks:
Swing (now in maintenance mode)
JavaFX (actively developed, led by Oracle and Gluon)
SWT (developed by the Eclipse Foundation)
For remote apps written in pure Java but delivered to users as a web app, see Vaadin Flow.
Yes, Java Applets are dead
Oracle has deprecated Java Applet technology, having proven too difficult to integrate securely into web browsers.
All the major web browser makers (Mozilla, Apple, Google, Microsoft, etc.) have phased out support for Java Applets.
Long live Java GUI apps
See white paper by Oracle, Java Client Roadmap Update, 2020-05.
Oracle’s vision for local Java GUI apps is for the developer to deliver a "double-clickable" app bundled with its own JVM slimmed down to include only needed parts. Modern tooling includes jlink and jpackage. Oracle no longer sees Java being generally bundled with operating systems, nor generally being installed by users.
While Java Applets are dead, Swing is still maintained as a required part of every Java implementation. People continue to write Swing apps for use on a local computer. You just cannot run a Swing app within a browser any longer. If you have source code for a Swing-based Applet, you can easily modify it to run as a local Swing app.
Swing’s replacement, JavaFX, is under very active development in the open-source project OpenJFX, a subproject hosted on the OpenJDK project. Releases arrive every six months, around the same time as Java releases.
The Eclipse Foundation continues to offer Standard Widget Toolkit (SWT) as a third platform (besides Swing & JavaFX) for writing Java GUI apps on a local computer.
For an open-source implementation of Java Web Start, see OpenWebStart. Oracle has dropped support for the technology, but others continue to find it a handy way to deliver and launch local Java desktop apps.
If you want to write web apps in pure Java using a Swing/JavaFX style of coding, see Vaadin Flow. Your app executes server-side in a JVM while the user-interface is automatically rendered remotely in the web browser by way of standard web technologies (HTML, CSS, JavaScript/ECMAScript/TypeScript, Web Components).

SE EE Netbeans compatibility [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm learning Java and I've been reading these books:
Head First Java, Head First Servlets and JSP to get started.
Up until now, I've been doing most of the learning on HF Java on Eclipse IDE for Java developers(not the EE one). I also installed Java SE 7.
But now I want to move on to HF Servlets and JSP. The book says I need only Tomcat.
I also wanted to familiarize myself with NetBeans, so I downloaded Netbeans IDE for Java EE from this page https://netbeans.org/downloads/index.html.
My questions are : 1. Should I download Java EE before installing this version of Netbeans? Does this version include the Java EE or should I download it from Sun page?
2. Is it overkill to install Netbeans for EE when all I need is Tomcat?
I will eventually learn EE I think... After these two books, I may read HF Design Patterns or HF OOAnalysis & Design Not sure if they're really necessary.
3. What would be the appropriate learning order do you think is ?
Your answers will be appreciated.
1.
Java EE is basically just Java SE with a few additional JARs for EE APIs like Servlets, JAX-WS etc. Installing multiple JREs on a computer will most likely lead to runtime issues because of the question which JRE is the default one, especially on Windows, since JAVA_HOME environment variable is not consulted in Windows Explorer, and tools like Ant and Maven depend on it.
For example, I keep several JREs/JDKs in one folder (unpacked, not installed) and list them in Eclipse to run applications I am developing on a particular JRE.
2.
When you, in Eclipse, do the following:
Window > Preferences > Server > Runtime Environments > Add...
and select Apache Tomcat 7, in the next step you can click on Download and Install... for Eclipse to download the latest Tomcat and set it up in selected folder as a target runtime that will run in the selected JRE.
You can also manually do the same and just point Eclipse to the folder where you installed / unpacked Tomcat.
When you then create the new Server for that Tomcat runtime you can assign a Dynamic Web Application project to it and it will be deployed on every change to the project. You can run it or debug it from inside Eclipse.
3.
Once you are on good terms with servlets and JSPs you should probably continue with the OO Analysis and Design, and then learn the Design Patterns. After those I recommend books on OSGi and Java Application Architecture.
Good luck.
If you install Netbeans EE, it will also install other goodies such as Tomcat or Glassfish. This will allow you to debug your EE application directly from the IDE, as opposed to having everything dumped into Tomcat logs.
I think that since you are just beginning, doing everything from your IDE will allow you to better focus on what you need to learn.
If you learn the usual coding standards and recommended ways in Java SE, you shouldn't have any trouble in moving on to EE. If you read more about OOP and other design patterns, you will be better equipped to build decent applications and also better understand frameworks which are already available.

Categories