How to deliver a Java program locally through a browser - java

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..

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

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)

If you feel comfortable with Java EE-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 Java EE 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.

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.

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!

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.

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.

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.

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.

Related

Migrating a 2-tier Java application to...?

We currently have a 2-tier Java Swing application sitting on top of MS SQL Server 2005. All the business logic is in the database. The client is quite old (and not very friendly), and for reasons of performance and scalability, we've already started porting some services to a middle tier in Java.
However, we still have a number of short and long term goals:
Pick a technology stack for a new front-end
This isn't easy - I can see everything from a web app at one end of the continuum to a traditional desktop app at the other being viable choices. The current front-end isn't really complex (mostly form-based), so I can see web/AJAX fitting, but it's an area where we don't know what we don't know.
Stacks on my list are:
Eclipse RCP, Netbeans RCP
Flex/Flash, Silverlight, JavaFX
Pure Javascript frontends (Sprout Core, Javascript MVC, ...)
Java-based Web frameworks (Wicket, JSF, ...)
Find a way of making the current application perform acceptably in a remote situation
We have some clients who resale our app to smaller clients and need to be able to remotely deploy it. Due to the 2-tier nature of the current architecture this leads to terrible performance (for example, calling a stored procedure that returns 18 result sets). We've used a Citrix solution in the past, but no-one likes that approach. Tunneling JDBC through port 80 also sounds like a bad idea. I was starting to wonder if there's anything that could use a X-Windows like approach to remote just the GUI part.
To simplify development and leverage your experience in Swing consider using Vaadin for your frontend. It is a Java framework for building modern web applications that look great, and perform well. All the code is written in Java and looks very similar to Swing.
As far as overall application architecture I would advise multi-tier, service oriented architecture. The best way to do it is by using Spring framework with Hibernate for database access.
If you want to easily redeploy your application, for an update, security reasons, etc. and if you want your application to be it to be accessed remotely, you should really consider a web based front end.
Plus, this way, only one app, your web app, will handle connection to the database, so no JDBC tunneling or whatever.
Concerning the best framework, it depends on your team knowledge, the way your application will be used (more or less javascript), etc.
We've just gone through a very similar evaluation process as we're migrating a legacy application.
For us the biggest deciding factor in what front-end framework to use was the prior knowledge of the development team. We wanted something that everybody would be comfortable with immediately. We had a couple of the senior developers that have worked with X or Y, but the framework that everybody knew was Swing.
In the end we decided on the NetBeans platform using RESTful webservice to communicate with an EE server.
As a bonus you can get your NetBeans platform application to deploy as a Java WebStart application, which means you get the benefit of not having to worry about individual installations.
If the frontend is mostly form-based, I would stay away from Flex. Flex is great for some applications (I'm using it for a canvas based application), but the form components of Flex has some usability issues. They just don't work like you expect from todays web. (like missing support for mousewheel, typing in dropdownlist only take first character into account etc.)
Assuming that you are going to force all your clients to install a new middle tier, I can't think of an argument against making it a Java web app. As already mentioned you have the benefit of controlling all access into your platform over HTTP, which allows easy resale, just with firewall configuration. There's no reason you can't make use of Javascript within a web front end, you may be interested in DWR, which allows you to interact directly with Java objects via Javascript. I've used this before to add some simple Ajax interaction to a Spring MVC webapp.
The reasons I like this approach, you're already migrating code into Java middle tier, so
Already imposing Java server hardware cost on clients, hosting app server / web server is comparable
Already have Java expertise, can be leveraged with DWR
Can use as much/little Javascript as appropriate (I've used DWR with IE6, Firefox 3, Chrome)
I think you're right to be wary of pushing too much functionality to the client, I'd go for as thin a client as possible. The only reason I'd look at the first two stack choices would be if you have some developer expertise in a particular area, and not Java webapp/Javascript.
I'd suggest to create a short list of candidate frameworks and create a small test application with all of them. This way you will get a sense of good and bad aspects from all of them and also get a picture what the community activity and documentation is like for each project (there is a lot of variance on those).If you end up doing this I hope you'll include Vaadin in your short list, I think it would fit you very well. If you have any questions just come over to our forums and we'll help you to get started.

Is it possible to create Desktop Application using Java backend & Web Technologies UI [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 months ago.
Improve this question
I would like to create a desktop application in Java & web technologies. The main reason for selecting Java is that it is free, open source, and hence our investment would be minimal and we would save lots of investment with respect to licensing costs, etc. Also, the main reason for selecting web technologies is because our current programmers are well versed with web technologies like HTMl, css, Ajax, and we have good experience in creating amazing UI in web technologies.
I will give you some idea about the software that we would like to create. It would be a desktop based software, namely something like an ERP software.
The key requirements are that there should be a great UI and it should be fast and not very resource intensive.
I have heard that implementing a great GUI is possible, but difficult in Java. It can be done but is complex, whereas it is pretty simple to do the same in Visual Studio, Microsoft products.
I have also checked Adobe Air, Nokia QT, etc but they all are pretty expensive for us and we are looking for front-end browser UI and backend embedded server/database using java technologies.
Is it possible to create a desktop software in which the UI is created using the web technologies and there is an embedded server (like jetty or tomcat) and database and the backend programming would be in Java. How does JavaFX fit into this?
So basically, the desktop application would have an embedded browser (mozilla or some java browser which can packaged with the software), but the end user should never realize this.
I look forward to getting feedback about the same. Can you please provide some examples of software created in a similar combination of java + web technologies.
I did study some softwares like PulpTunes & Zimbra which were along similar lines, but they seem to be connecting to internet to display data. Our software would be totally an offline desktop application.
First of all, it is possible. If you are looking for example, check http://wiki.eclipse.org/Hudson-ci/Meet_Hudson.
You can get basic architecture if you dig into their code. It does not use any embedded db.
You are saying your application will always be offline, in that case I suggest you to go for pure desktop application using technologies like Eclipse plugin development.
If you already made up your mind, here are some points that can help you based on my experience with similar application,
Although your application is offline(I assume, your application need not connect to any server for any use case but the user machine can access internet ), you need to deliver changes(for example, change in html or jsp page )/bug fixes transparently to end user. JNLP/Java web start is a good fit for this.
If you are going for JNLP way of installing, you launcher should take care of embedded db installation and ports at the end user machine(this is big problem than it appears).
Also if you are launching server(in my case, Jetty) through JNLP, you will come across Class loading errors due to permission issues. Be prepared to dig through server code. I have done it long time ago and I do not have code now to point exact issues.
Show progress bars during installation process and during your application startup. Your war deployment takes some time and user needs some of knowing that application is startup is in progress. You will end up writing some swing UI.
Launch URL of the application automatically in default browser of the user system, after application startup. You do not need embedded browser.Check http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/.
I used MySql as embedded data base. Check Embedding mysql in java desktop application. It worked for me, I did not come across any problems.
Yes, it is possible. See https://github.com/jreznot/electron-java-app demo. There you will find an easy way to build Electron based application on Java, without compilation to JS, just Java application inside of embedded Jetty instance with Vaadin UI.
You are truly right, java is great if you are developing a project by self.
Server side coding can be done using Spring (For MVC, Database etc...Very rich and ligthweight framework, easy to learn and understand) with hibernate(ORM framework for Database handling, provides dialects for any Database server).
For UI, you can use Spring MVC OR JSF OR GWT OR javaFX. JavaFX provides JNLP download, which runs on java and without browser. check the link for more JavaFX samples. http://javafx.com/samples/
So its on you, what you want to use for UI side. If you prefer web UI (Not javaFX i mean) then you can have many options.
For Ajax, you will have libraries which support easy ajax. like DWR (Easy Ajax, JS to JAVA) and many other JS libraries like yahoo, jQuery etc.. can be used.
hope this helps.
IMHO the whole idea of running a web-server just to create a desktop app with js and ajax and stuff is horrible... I heard about Apple-creator Titanium which is allows to create crossplatform apps using web techniques. There are couple other similar programs as well.
I think you'll end up better buying a good wyswing Swing design tool for java ui which will cost you couple hundred bucks but will save you lots and lots development trouble. It is very hard to believe that laying out a nice desktop app is more complicated than laying out a web page.
I didn't get the embedded jetty/tomcat part. You want the desktop app to run an embedded server that talks to the database? So each desktop app would open a DB connection?
Why not have a Java desktop app that sends HTTP requests to a JavaEE server that connects to the DB and processes the requests? So basically, a Java client (which could be as rich as your developers can make it) replacing a browser. This gives you a lot more scalability, etc.
We have a similar (albeit much more complex) product developed using
- Swing + Apache Commons HttpClient on the desktop. This makes an HTTP POST request with serialized binary data to the server.
- A dispatcher servlet running in a web container that recreates the Java object on the server and executes the request.
I will probably get stoned for this, but I suggest JavaFX for this. We have successfully implemented a JavaFX-application for internal use in a larger company. The advantages are that the software is "controlled" on the server side (thus, nobody will have an "old" version). Installation effort is minimal (Java Web Start fixes this for you, it will even trigger a minimal JRE-installation if none exist) and last but not least, JavaFX can be run in the browser and as a pure desktop application alike without having to change the code.
Adobe FLEX is another contender, but it lacks the "Web Start" bit and is not quite as flexible when it comes to easy migration between browser and desktop.
Anyway, JavaFX is not quite feature complete as FLEX but version 1.3 can be considered battle-ready and you can create neat stuff with the free JavaFX plugins for Adobe Creative Suite (if your app will contain any graphics, that is).

Java web app as desktop app, which frameworks should I choose?

I need to make a web app that I would be able to install as a desktop application on a client PC (database, jetty+war, firefox/chrome/sth portable).
The application is a quite big search app (I MUST use Lucene). There are only few screens, some dependencies in search queue, etc.
Now I need help in choosing correct components. Application must be:
Light - minimalistic and user friendly frameworks (Java + JavaScript)
Efficient - working on old PCs and working fast
Developer Friendly - I would love to write it with pleasure ;)
So my questions are:
Do you have any suggestions about choosing components?
What frameworks, what obfuscator?
Do you have any comments about making a web application a desktop application?
What are the main risks?
Many Java web apps distributed in this style are done so alongside a lightweight application server or web container such as Jetty or Tomcat.
When you click to start the application, this actually starts the container which internally hosts your application. (You're application can be packaged as a WAR internally.)
For lightweight databases, possibly look at SQLLite, HSQLDB, or Apache Derby. These can also be distributed alongside the application. Or maybe you can just collect database credentials as part of your install process and let the customer maintain their own database.
The arrangement you describe will involve work and custom scripting. You're going to the trouble of creating a thin, multi-user, web application and then throwing away the main benefit - the shared single instance. Customers, eh, who'd have them! :-)
Maybe you could take a look at Google's GWT. You can write Java code and it will then "compile" it to JavaScript. Using it feels like using a desktop app. Gmail, Google Wave,... have been created using this technology.
I think you don't even need a webserver, but the compiled result is pure JavaScript + static HML pages. If you then create a Chrome application shortcut it'll really look like a desktop app ;)
The only thing is that the learning curve will be a bit steep initially but if you're eager to learn, then it's really cool stuff and you can manage it easily.
Ha, I'm in the same boat. But I have many screens like normal web apps.
My suggestions is:
1, take web easy, no framework. Since there's little web pages, html+jquery+css is recommended;
2, lightweight database is not important. Because mysql does cost little memory, and it's user-friendly, large community.
3, So pay your attention on your search engine, and happy coding.

Integrate a Java stand alone application to the Web

I develop Java applications with Eclipse that process data. So far I only developed stand alone applications that take data from file or database, process the data, and output the results to the console/file/database.
I would like put my application online. I never did any web development, but from my understanding, the only difference is that my code needs to be on a web server that can get http requests from users, and return http response based on my application's result.
I would like to get advice on the easiest way I can do this. What technology do I need to learn and what tools I can use for making the transition easier. I would also like to separate my code from the code related to the web stuff.
Thanks a lot!
The simplest approach to developing Java web applications is via the Servlet specification. This lets you load your application into a Servlet container (such as Jetty or Tomcat), which handles the HTTP-side invocation issue. Your servlet is then a front-end for your front end agnostic processing application.
Since all applications require a user interface, take a look at the myraid of possible templating languages available. Velocity is always a safe pick. This will help you seperate the user interface from the adapter code.
While you investigate alternatives, Java Web Start may be the fastest way to get your existing application online. Here's a trivial example.
The easiest is most likely to learn how to write a simple servlet, how the HTML looks that you want to generate and then adapt your existing application to run inside the servlet code, and print html instead of just plain text.
This is described in the Servlet part of the Java EE tutorial (which is not great, but a start)
http://java.sun.com/javaee/5/docs/tutorial/doc/bnafe.html
If you want a more accessible book, I can recommend the Head First series. http://oreilly.com/catalog/9780596005405
For a web container, Apache Tomcat is fine. http://tomcat.apache.org/

Develop desktop applications view with HTML, as a web application

I am used to develop web applications in Java (Struts, Spring, JSP...). But now I want to develop a desktop one. I never liked to design windows in Java (AWT, Swing, SWT): too much work for an ugly interface. So I think it could be a good idea if could take advantage of my web-app skills. One option is to modify the SWT Browser and make calls to a Java function instead of HTTP requests. A very good add-on would be use of JSP. Finally, I thought that probably there is some framework or tool for this.
Do you think that what I propose is a good idea?
There is available some framework for this?
I need this for light applications. So I think that embedding an Tomcat server and using it with HTTP requests is not a good idea.
Edit: One example application could be a folder comparer: you specify two folders and the app shows you which folders and files are different. In this case, I think opening an external browser is ugly. Bloated application (with its server, MVC, etc) wouldn't be the best choice.
If you have used the JavaScript library - ExtJs - then you can use it with Adobe AIR to build good looking desktop based web app.
Building app's in Adobe AIR is also simple and elegant with the flex builder ide.
If your option goes to embed a light server, check winstone is not fully J2EE compliant but should be enough for what you need.
About the browser, I am not a big fan of swt myself, it complicates a lot cross-platform deployment, so probably worth to keep an eye on jwebpane, not quite ready yet, but probably the solution you'll need.
I wouldn't discount embedding a web server. I've done this before with a web start application embedding Jetty.
The download was pretty fast, the server starts up and you can use BrowserLauncher to immediately drive your browser to the embedded server, and hence your application. Jetty is designed to be modular and have a small footprint, so you can probably cut it down to the bare necessities.
There are several options: You can use the plugin API of Firefox and develop your app in there. You can use HTML, JavaScript, the built-in database, all the browser features and access the OS level.
Or you could try PyQt (Python and Qt) which allows to write simple applications very quickly.
[EDIT] The main problem you're facing is security: For security reasons, JavaScript apps (running in a HTML page) can't access local OS resources. So unless your browser allows you to write plugins in JavaScript (which is only true for FF AFAIK), there is no way to write an application which uses HTML as the "view" without the help of something else.
Moreover, HTML is very limited when it comes to features for applications. HTML is designed to be a "static document view" not an "application". You can do things like GMail but if you compare GMail to any real mail app (Outlook, Thunderbird, Notes), you'll see quickly that real desktop apps offer a lot more features.

Categories

Resources