tags:

views:

124

answers:

3

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.

+1  A: 

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.

Peter D
+1  A: 

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.

Cameron Pope
A: 

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.

Charlie Martin