How can a java library be ported to the web? - java

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.

Related

Embed a Java applet in a Web Project

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

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.

Making a Java Application available via a Web Browser

I am working on a Java program that has bunch of classes consisting of dialog boxes, JFrames, etc.
Can someone guide me where I can learn how to transform it to an 'applet' kind of. ( I don't even know if applet is the right word)
Like for example, can it be accessible through the internet browser. If I somehow make a domain www.myjavaprogram2011.com it would be nice if it will take it straight to the java program I coded. I see this as anyone can come to this website and use that program.
Thanks!
You may want to look into Jars for distribution or probably more aptly Java Web Start as this allows Clients to be downloaded and run.
Java Applets isn't your best bet as there's lots of security permissions that you need to worry about as well as your jars needs to be signed (especially for client/server data access).
Try using Java Web Start, it will allow you to launch fully-featured application from the Web Browser. Oracle has tutorials on deployment of JWS, etc.
Sounds you're looking for some kind of RIA technology. Have a look at JavaFX, though it's not mature yet IMHO.
Ah, but then, if you already have a Swing application then this isn't an option probably.

Is Google Web Toolkit similar to AWT and Swing

I've looked breifly into GWT and like the idea that I can develop in Java and have the application compile down to HTML and JavaScript. Is the concept behind GWT and AWT and Swing the same or different?
It is programmed very similarly(patterned after Swing) and the code is 100% java (compiles with a standard Java compiler without errors), but the way it works is very different. Instead of compiling into a Java app, it compiles into Javascript that is sent to your browser.
This ability to program good active Javascript without actually coding Javascript and HTML is pretty nice.
Also, since it programs much like swing, you can do stuff like adding listeners that effect other controls pretty easily.
GWT is very much similar to Swing in its usage of Widgets, Panels and the EventListeners it provides. A different way to look at GWT is to think of Javascript and HTML as Assembly language and GWT as a sort of High level language which generates Javascript and HTML. With GWT its easy to develop desktop-like apps for the web using the same tools you would use for building a desktop app
Define concept.
AWT/Swing are used for desktop Java apps or applets. They both require JVM to run.
GWT is used to translate Java code to Javascript. This only runs on Javascript engines, i.e. browser.
The API design, as stated above, is similar to Swing. You get the same Panels, Buttons and other Component classes as in Swing.
AWT and Swing are for programming stand-alone applications (and to a lesser extent, applets). GWT is supposed to make programming web applications similar to stand-alone apps. I wouldn't program a non-web app using GWT.
GWT is conceptually similar to Swing, but is more a replacement for JSPs than anything else.
GWT is a javascript toolkit that allows you to write the javascript in Java. The only real similarities to Swing and AWT are that they are toolkits for creating user interfaces and they use Java. The end product is different and the real purpose for using them is different. GWT gives you the ability to generate a ajax user interface for a web browser while the other 2 give you a console (or applet) java app. In my mind the real reason for using GWT is to get a quick ajax interface up for prototyping purposes. But I dont think its really production ready- ie I dont thing Google uses it in their own webapps. A better choice for more robust ajax webapps is http://developer.yahoo.com/yui/ or http://script.aculo.us/.
disclamer: While I do work at IT Mill, this is just for information to the original poster. This isn't marketing spam.
If you like the idea of being able to write Java and get a webpage out of that, you might be interested in IT Mill Toolkit. It's a toolkit for making RIA software on top of a J2EE stack, and it uses GWT heavily.
One of the basic ideas are that the code generated by GWT is just as prone to client-side forging attacks as any other JS/Ajax-traffic. IT Mill Toolkit makes sure that the data is validated server-side too.
The toolkit is also designed in such a way that if you are familiar to Swing, you should have no problems picking it up.

Best server-side framework for heavy AJAX Java application

There are zillions of Java web application frameworks.
95% were designed before the modern era of AJAX/DHTML-based development, and that means these new methods are grafted on rather than designed in.
Has any framework been built from the ground up with e.g. GWT + Extjs in mind?
If not, which framework has adapted best to the world of forms with dynamic numbers of fields and pages that morph client-side?
Echo2 / Echo3 by Nextapp (www.nextapp.com) is totally awesome.
Advantages over GWT:
1) It is not limited to a sub-set of java like GWT
2) It is easier (in my estimation) to learn
3) Has extremely robust design studio for almost drag and drop designing.
4) It is very fast, and works very well on all platforms browsers
5) You can write your application using either java script or java
6) It has great and straight forward methods for handling events and actions.
Personally I think that for any web-application in which you are trying to integrate java and speedy delivery I wouldn't hesitate to pick Echo3 or Echo2.
If you're starting from scratch. I'd have to say Google Web Toolkit. I have to say it is incredibly powerful. You get keep using most of your Java tools. Plus, you don't have to duplicate code that exists on both the server and the client, it just gets compiled differently for each area.
I'd consider REST-style frameworks as well as the other recommendations here- Restlet or Jersey may be good choices for the backend, while you use something like JQuery or GWT on the front end. Both frameworks can easily produce JSON, and the REST style provides a nice clean line of demarcation between your client application and your server source; I find that JSF can make that demarcation pretty muddy.
I use JSF and IceFaces. Although JSF has a few limitations, IceFaces seems to work pretty well and has ironed out a few of the problems with JSF.
I haven't used a really good AJAX Java framework as yet, although Echo2 looks interesting.
I like the stripes framework. It lets you use whatever javascript toolkit you want.
Here is their documentation on AJAX
GWT is quite powerful and easy to use (all Java, no Javascript/HTML/CSS coding). If Google has their way it will be a dominant framework/tool in web applications development, and for good reason. It already works with Google Gears (which allows offline access to web apps) - and more than likely will be optimized to work within Google Chrome.
DWR
I use this to dynamically populate drop downs, and even filter them on the fly based on user input in other places on the form.
I like the combination of JBoss Seam and Richfaces, especially with the JBoss tools that are extentions to Eclipse - makes building these sort of RIA's incredibly easy.
Wikipedia contains some useful comparisons:
Comparison of JavaScript frameworks
List of AJAX Frameworks
Your choice depends on several different factors including whether you want the "work" done client-side (most javascript frameworks) or server-side (echo2 etc.). Other things worth looking at are tools like OpenLaszlo that provide Flash (I think) out of the box, but drop back to DHTML if there is no Flash player present.
Unfortunately I think the decision comes down to balancing several competing cocerns. Check out the comparisons and try them out - most come with online demo's for you to try.
Aptana has a server side frame work called Jaxer. This is from their site:
Jaxer's core engine is based on the same Mozilla engine that you'll find in the popular Mozilla Firefox browser. This means that the execution environment you use on both the client and the server are the same. It's Ajax all the way through and through. That means you only need one set of languages -- the languages that are native to the browser -- to create entire applications.
This framework is open source and has a very nice IDE based on Eclipse. Aptana is also working on a Javascript implementation for ActiveRecord called ActiveRecordJS. Potentially you could use this both client and server side with their framework.
GWT is one of the best AJAX framework that I used ever. Most important thing about this framework is that its maintained by Google. And Everyone know "Who is Google ?"
GWT is used by many products at Google, including Google AdWords and Google
Wallet. It's open source, completely free, and used by thousands of
enthusiastic developers around the world.
GWT provide rich widgets that can be used to built any application. Almost all the widgets they have.
Another important point is GWT is continuously developing and its also have stable release which is very good thing. Another thing Google has also released GWT-Material which is again a very good thing because everyone is moving toward material.
I hope this will help you!!!

Categories