I have a Java Swing project for my class. I would like put it on my website so people can use it. However I'm not sure if there is a way to turn it into a servlet. Or do I need to know JavaScript? I'm confused. Is there a way to make my swing application into a servlet automatically?
Instead of a JFrame you have to use an applet, which is similar, and have to embed zhis in your webpage.
Have a look on Java Webstart, too!
If your application is a big commercial one, you can use Ajaxswing for (nearly) automatic conversion.
Otherwise you should rewrite it. If it has been written well - that is, with separation between UI and business logic, you would only have to write the UI, and reuse the business logic. If not - here's a lesson learnt on how to structure your code.
Servlets are generally used in Java to create dynamic web applications and web services.
If the intent is to port a Swing application to something that can be used from a web browser, probably the approach would be to either:
- Port the Swing application to an Java applet
- Use Java Web Start
For launching Java applications with a graphical user interface that runs on a client machine, the approach would not be to use a Servlet, as it will require a server which runs a web container such as Tomcat or GlassFish.
If you just want to provide the application as-is on a web page, where people can then click it to run it, the technology you want is "Java Web Start".
This will require you to learn to write a JNLP file describing what jar-files your application need and bundle with the rest of the files.
If your application needs to use resources outside of the normal sandbox provided, you will either need to ask for them explicitly using Web Start methods, or say in the JNLP script that your application needs unlimited access to the machine, and then you must sign the jars.
You may also just simply create a single jar, where the manifest inside says what the main class is, and then let people download that, and then double-click the locally stored file to run it. That would be what I would recommend for now, as it is the simplest approach.