views:

370

answers:

9

Hello,

I want to write an application that runs entirely locally on one machine - there is no need for connection to the internet or to any external machines.

I was thinking that it would be a good idea to use a web browser as the platform for this application so that I would not have to mess around with lots of UI stuff - I could just knock together the web pages fairly quickly and take advantage of CSS to get consistent styles throughout the application.

However I want to interact with a MYSQL database on the machine in question. With this in mind I was thinking that I could somehow use Java to process the information that the user inputs from the application and communicate it to the database via JDBC.

I know that I could use an applet to do this but the downside to that is that I would like the user to be able to save files to the local machine - and I have read that applets run in a sandbox which prevents them from gaining any access to the local machine.

I also know that I could use PHP but I would like to take advantage of object oriented design which Java is perfect for.

Does anyone have any thoughts, suggestions or links to tutorials/webpages which could help me to decide how best to go about this.

Any thoughts are very much appreciated..

+2  A: 

If you feel comfortable with JEE-based web development, you could probably just bundle your application with Tomcat or Jetty.

If you do not want to run standalone servlet container just for one application, you can also embed Jetty into a runnable Java application (see documentation here).

Either way you can leverage existing JEE frameworks (Spring JDBC, Hibernate, all those web frameworks) for abstracting away technical complexities, although with embedded Jetty, you'd probably need to write some kind of integration layer for the web application framework of your choice.

springify
Another alternative to Jetty / Tomcat is Winstone - a really simple servlet container http://winstone.sourceforge.net/
Simon Groenewolt
Thanks, I'll have a look into this. I have experience working with the JBoss app server, are Tomcat and Jetty anything like this?
Scottm
Tomcat and Jetty are pure servlet containers, but from what you described, that will most probably all you need. If you need "true" enterprise capabilities without using a full-fledged JEE container, you might as well have a look at the Spring Framework.
springify
+1  A: 

I think you should give Restlet, a lightweight rest framework a try. The tutorial shows you how to start a local webserver, and by that deliver a "Hello World" through the browser within minutes (no joke!), and there's plenty of extensions for any kind of need.

In combination with Java Web Start by which you can deploy and start the application to the local host this should be what you need.

dhiller
+2  A: 

Grails may be a useful starting point. It'll provide you with a web server solution that's standalone, and it'll look after the JDBC requirements and the CRUD (create-read-update-delete) capability via dynamically generated web pages. It should take minimal effort to put together an app providing your database interfacing via web pages.

(fyi. Grails is the Java equivalent of Rails)

Brian Agnew
This sounds really interesting. A colleague of mine always speaks highly of Rails, so if this is anything like it I'm sure it will be good. Thanks for your answer.
Scottm
A: 

Using JDBC doesn't mean that you have to write an applet, you can use JDBC in any kind of application: a desktop application, a web application, EJBs, MDBs, etc.

You want to use a browser and Java on the server side? Then go for it and use Servlets / JSPs. Consider maybe using an presentation framework (Wicket, Struts2, Spring MVC,...), Hibernate for data access and Spring for other facilities and wiring. Grails is a good idea too.

BTW, I'm not a PHP specialist but PHP has object-oriented capabilities (introduced in PHP4 , enhanced in PHP5) so you won't sacrifice everything if you choose PHP.

So it really depends of what you want to do. If you want to write some Java (webapp or desktop app): choose Java. If you want to put quickly a few web pages in place and have an apache server, choose PHP. If you look for really high productivity, go for RoR or Grails.

Pascal Thivent
Yes I had heard that PHP has some of this functionality in it. I also agree that you can quickly knock pages together with PHP - I'm doing this as we speak to make a little prototype.Grails has also been recommended by another poster, I will have to look into it. Thanks alot for your answer :)
Scottm
np, you're welcome.
Pascal Thivent
A: 

If you want to do it as an applet you can. Sign the applet and give it permissions to the local network (to connect to the MYSQL server that way)... that should be possible. Here is a tutorial on it.

TofuBeer
+5  A: 

I know you said you don't want to mess around with GUI stuff in java, but have you looked in to java web start? It does almost exactly what you need; a user clicks a link through a web browser and your application is deployed on their machine, it even checks to make sure the right JVM is used. Because it is a full application and not an applet, your app won't be sandboxed, and you don't have any access restrictions in your program (other than the normal java stuff..), and for example, it would be easy to do what you mentioned and talk to a mySQL DB. The only downside, is what I mentioned earlier, is that you would have to design a UI in java.

Web Start Wikipedia Page

Sun FAQ on Web Start

nstehr
A: 

Hi,

as someone suggested already you can use embbeded jetty server on your application and just let your user to start it using somekind of shell script or batch script. You only need to make your layour directory complaint with a Java Web Application and your on it. ie:

MyApplication
   app/
      WEB-INF/
         lib/
         classes/
         web.xml
   start.bat    |
   start.cmd     -  depends on your client OS
   start.sh     |

Then you should only need to take care of launching Jetty in your start.[bat|cmd|sh] with your app as your webaplication context and your done!

A: 

You can try GWT + Google Gears

GWT is a GUI toolkit similar to Swing for the browser. Google Gears is a browser side database. Your app is completely in Javascript in a single HTML file and cross-browser compatible.

GWT app can make Server calls and Gears can sync up with a Server database. So you need not restrict your app data completely to the local desktop.

Sathish
A: 

If you're interested in some experimentation, like new stuff and would like to reuse the plethora of Java libs (including JDBC) then you might be interested in the lift web framework, which is Scala-based.

01es