Embed a Java applet in a Web Project - java

The company I work for has one of their main products written in Java, it is an applet made up of numerous sub programs.
Our goal would be to develop an alternative GUI to the current Java using Web technologies and build it to be cross-platform. The applet is very large and it is therefore necessary to implement this transformation gradually.
To achieve this we would like to gradually replace the individual applet programs with their corresponding HTML/CSS/Javascript version.
Is there a "container" (so far I have taken into consideration Electron, Qt and, the new kid in town, Tauri) or a stack of technologies that allows you to start a Java applet within it?

You might consider using CheerpJ: A fully Web based technology designed to run unmodified Java applications (including GUIs) on any modern browser.
https://leaningtech.com/cheerpj/
Beside running the whole application or applet as it currently is, you can also use the JavaScript interoperability API to build a pure HTML5 Web app on top of the existing Java code.
https://docs.leaningtech.com/cheerpj/Runtime-API#cjresolvecall--cjresolvenew
Full disclosure: I am lead dev of CheerpJ and CTO of Leaning Technologies

Related

Java Application on a webpage

I have a complete and pure Java project (GUI game) which I want to run it on my website.
What is the best to do without creating the whole java project from scratch or is there any technologies I can use to embedded my java project on my website.
I know it became more difficult to do this as most broswer do not support java anymore. I know there is a way to do using Java Web Application using Apache Tomcat, but I do not want to do route. I am trying to find more easier and better to solution to this
Thank you
Unfortunately, It is quite possible that you need to rewrite some parts of your application. Mainly because it is a different language (I assume SWING, AWT, or another Java-based library, but you could tell more about your project and used libraries).
There is usually two parts of a game/application (super simplified):
backend,
frontend,
I am quite sure you can use most of your backend code. But the frontend probably needs to be rewritten. It is even better if you loosely coupled those two parts meaning there is no code in the backend for the frontend because you will have a harder time now breaking it down.
For example, you could check Vaadin and see what you could use from there to refactor your GUI application to be work on a plain browser.
Vaadin basically lets you write only or MOSTLY Java code and still create a website, webpage.
Good luck!
p.s: Next time I recommend you (if you wanna publish it to a different platform) a cross-platform language, you write once and you can run it publish it on multiple platforms.

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.

Options to re-using an Applet's existing code?

After five and a half years full-time work on a product ranking engine project, which revolves around a 64,839 line applet, the browser companies have seen fit to dump applets.
At this point I am in no position to convert the applet to another language (unless I get a huge injection of funds to hire a team of programmers). My partner is not going to support me for another two years.
I know the questions are rather vague and I should be keeping up with the latest tech, however I've had chronic earaches for 14 years that affect memory and concentration, so programming is difficult enough without trying to keep up with the latest developments in software as well. The reason I am asking for advice is that I don't want to make another monumental screw up.
Question 1: My understanding is that Java Web Start launches the application, but it then cannot communicate back to the JSF web page any more (JSF2.0). Is there any way of getting around this?
Question 2: Can anyone suggest any other options other than re-coding the whole thing?
Question 3: Is it likely that applets will be altered to use the latest plugin format or are they gone for good? Does anyone have any inside information on this?
Overview of the applet's requirements:
The applet allows a user to customise some or all of the product ranking criteria, which has been preset by a panel of knowledgeable experts, to their own particular needs. The criteria is stored and edited via graphs (custom painted jPanels).
The ranking criteria can be altered entirely using the mouse (to change the graph shapes), though some values can be entered using the keyboard if the user wishes. Once customised, the applet is then used to submit the changes to the ranking engine server.
It is also used to allow third party experts to alter the ranking criteria to create their own product usage category ranking criteria. The third party expert can then place links on their own web site that will allow users to rank products using the third party expert's own ranking criteria. This allows anyone to create their own ranking criteria for use by others.
The applet uses a plugin bean that is also used in a standalone Java editor application, which is used to create a product usage ranking criteria file from scratch (the editor is 77,710 lines of code, though 61,257 lines of that is the plugin which is also used in the applet). This means most likely having to convert the editor as well, as the two are inextricably linked. The plugin basically is the applet and also the editor.
The plugin can capture, edit and store ranking criteria for virtually anything the human brain can rank. Thanks to the graphs, it can use any attribute that the brain uses, and for which we have no formal system of measurement; hence why the applet is so damn big.
Your question is probably too broad for Stack Overflow, but I'll give a brief response.
Java Web Start
Java Web Start is probably the best route for you. This technology is basically a convenient way for a user to obtain, install, and run a Java desktop app. The web browser is only used to initially download a small XML file describing your app and where to get the app. The Java Network Launching Protocol (JNLP) defines these pieces of information stored in that XML file. Your app will be downloaded from a server, and saved to the local machine. A Java Runtime Environment (JRE) can be downloaded and installed if need be as part of the process.
By default the app runs within a security sandbox similar to Java Applets. But you can sign your app and define security protocols to break out of some of those restrictions including making network connections.
The bulk of your programming would remain intact. The app is still pure Java, running in a JVM. You would need to do a bit of reprogramming to be a desktop app rather than packaged as an Applet. And you would have to learn about easing those sandbox restrictions. And your app will have a menu bar of its own as a full-fledged app, so you may want to take advantage of that. But the guts of your app would remain the same.
Over the years, Sun & Oracle have put efforts into improving Java Web Start. Unfortunately it came too late after Java-on-the-desktop had lost too much mind-share. And Swing never got the overhaul it so desperately needed. So Java Web Start never went big-time. But Java Web Start does work as advertised, so give it a try.
While there were some security issues years ago, I believe they have been resolved long ago. The many infamous security problems with Java were largely involving the web browser plugins bridging between browsers and the Java JRE; those problems do not affect Java Web Start (though you should do your own research to confirm).
For the general public, Java Web Start may be too much to ask of new, anonymous, and less-motivated users. For a commercial product with a user-base of eager customers, it may the perfect solution for you. I suggest you do some more study, read the Wikipedia page, study the Oracle technology page, look at the Tutorial, read this overview by John Zukowski that includes an example of network (making socket connection to time.nist.gov), and so on.
Vaadin
The Vaadin framework is an open-source free-of-cost professional user-interface development framework that uses pure Java to run your app on a server in a Java Servlet web container while automatically generating a user-interface using standard web technologies (HTTP, HTML, CSS, JavaScript, GWT, WebSocket, etc.) for presentation within a regular web browser (Firefox, Chrome, Safari, IE, Edge, etc.). As a graybeard, I think of Vaadin as an X Window System for the new millennium: The user interacts with screen widgets on their local computer but the business logic of the app is executing on the server, and the server is updating the remote UI as a result of that business logic executing.
Vaadin is not yet-another-web-templating system. Instead, your app is written in pure Java. No need for you to learn the alphabet-soup of web technologies listed above. Vaadin takes care of that for you, auto-magically. You say in Java “I want a label, then a field, and a button” and Vaadin makes those appear in the web browser.
Using Vaadin would allow you to retain your Java code for the business logic part. But you would need to re-write the user-interface parts to use Vaadin widgets instead of Swing widgets. This would not be so terribly difficult as Vaadin was inspired by the general style of Swing, defining layouts governed by layout managers in which you place your various widgets (fields, labels, buttons, etc.).
Vaadin can make very professional business-oriented apps that feel almost like desktop business apps. Tip: I prefer the Reindeer theme for business apps over the newer Valo theme.
But you mentioned some kind of free-form drawing canvas in your Swing applet. That may be a sticking point. I do not know of such a widget for use within a Vaadin app. I am not saying there is no such thing, I just do not know of any. There are slider widgets that may useful, but I don't clearly understand your needs in that regard.

What applications or libraries are available for screen scraping applications on Windows?

We develop an application that clients use side-by-side with in-house custom software. One of our clients has requested that we investigate the use of screen scraping software to provide a sort of integration layer between the two applications.
Our software is written as a Java (QT Jambi) desktop application, which hosts a web browser control, that runs the application in Javascript.
The client software is a Windows desktop thick client. Unsure what it is written in (managed .NET or unmanaged win32? Maybe even Java).
We need to get data out of our application, and input it into their application. Their application can not be modified under any circumstances. They have suggested using screen scraping to read the information from our app, and input into text fields within their app.
Are there any screen scraping applications that can be used for this purpose? Are there any libraries that use some kind of OCR tech written in .NET? I think I want to avoid the type that hook into WM_Messages, but I'm unsure why.
Any pointers in the right direction would be appreciated.
What about making Windows API calls to interact with the GUI controls directly? If its written in .NET, this should be rather straightforward.

How can a java library be ported to the web?

How do you take a java library that is for the desktop or an applet and make it so you can use its functions for a web page? I know not all things are meant for the web, but can you call a "regular" java class in an apache/tomcat setup server and it "work"? Do you have to so something to it to get it work with a web page?
I was interested in jgrapht for the web but it looks like all desktop or applet and I don't know that it would be possible to return its graphics to the browser, but maybe its libraries and a generated .png rendered by the browser.
Although there is debate on applets being alive or dead, I am not interested in using one at the moment, as it appears it is dead, albeit with new possible life in the latest update 6u10. I don't know that I want to invest in JavaFX either.
Johnny, the thing is that you have to decide what you mean to do. You could, for example, use JGraphT in server side code; the graph could be visualized in a bunch of different ways, like JGaph or graphviz. Then you would output the visualization in some form that works on the web and put it into your web page. In JGraph, that probably means a print interface that generates SVG or PNG.
Or you could emit the graph structure as JSON with a simple walk of the graph and interpret it on the fly in the browser using Javascript.
It's hard to answer the question generally, because it strongly depends on how you mean to use it.
Yes, it is possible to use a java class or jar file in a web appliaction, but it also depends on what you want to do with it.
For example if the library is for mathematics and you want to return results back to the users on a web based application, this is definitely possible. There are many other examples I can give but they are all the same.
As for displaying charts, I have successfully used JFreeChart in a web application using Apache Wicket (which rocks btw).
So to answer your question, you don't really need to "port" the library, you just need to use it and display it's output to a web page instead of a java desktop GUI.
Of course their might be some libraries that are specifically designed for Java GUI stuff like Swing or AWT. But for the most part there is no difference in using a Java library in a J2EE environment or a J2SE environment.
There isn't a closed-form answer to what you are suggesting: porting a Java Library to a browser's environment and using its functionality.
If you are interested in graphing things, here are a few things you can try:
Open Flash Chart - a scriptable flash app that will produce graphs
Bluff - a Javascript library that produces graphs
processing.js - a port of the excelling 'processing' library to Javascript
As for accessing Java-based functionality in the browser, there are some approaches for that. One is to use a toolset like GWT that complies java into an HTML/Javascript/Java application. Another is to use an AJAX-based technology like Direct Web Remoting. It really depends on what you are trying to accomplish.

Categories