The required user interface is fairly simple; basically, two tables that "interact with each other", e.g. certain rows in one table get highlighted when a row in the other is clicked, plus maybe a panel with charts.

Is it possible to have a (largely) single code base for a desktop app and a web app implementing this interface? For a few reasons, it would be good to have both versions, but I would hate to implement the GUI twice.

The details of my particular case are as follows:

  1. This is an academic research problem, so I don't have strict constraints in terms of tools and the coding style (or users!). On the other hand, I do have quite some time constraints.
  2. It has to run on bare JVM, but any language/framework would be welcome (Java, Groovy, Scala, Clojure, etc.).
  3. There is no persistent state, i.e. no strict need in a shared DB or any server part whatsoever.
  4. I would be willing to go through some design hoops to make it work (by design hoops I mean some unconventional application architecture).

Is it completely crazy to even think about something like that? If no, what would be the tools to pull it off?

  • 2
    PS: I realize that it is most likely a far-fetched setup. My current instinct is to implement it as a web-app and then package it somehow in order to enable running it locally on Jetty, maybe wrapped in a simple embedded browser. – wxd Jun 23 '14 at 9:47
  • 4
    You've just answered your own question with that comment. AFAIK there are no frameworks that do what you want, the Web/Desktop models are too different. – Binary Worrier Jun 23 '14 at 10:04
  • I gather that you're asking if there's any way to only write the GUI once (there is, but it's just making a web app), but if you build using an N-Tier/Hexagonal architecture then it would be entirely possible to create separate web and desktop versions of the application where only the UI layer is different. This obviously allows you to share the business logic and database access code, but obviously you do then need to maintain both versions of the GUI. – Mr Cochese Jun 23 '14 at 10:15
  • See server2go-web.de - I guess that is what you are looking for. – Doc Brown Jun 23 '14 at 13:11
  • 1
    Groovy has Grails as a framework for the web and Griffon as one for the JVM desktop as two separate frameworks, but Griffon began its life by being forked from Grails so perhaps there's some scope for common codebase there. Just a thought. – Vorg van Geir Sep 21 '14 at 11:59

A browser is a desktop application, its very easy to pack your war with and embebed server (with jetty its really easy), this way you can run your app in a stand-alone machine.

If you want two versions, web and desktop, its because one of this versions gives things to your users that the other versions cannot give, if you are thinking in a "automatic" way of having the two GUI's its because you are thinking in having basically the same app in the browser and in the desktop version, ¿why you are thinking in wasting your time for building the same thing twice?

In resume, the problem its not thinking in an automatic way of having two guis, the real problem its thinking in why do you want this two versions in the first place.

  • I think your point about the benefits for the user is right on the spot: the only one who would benefit from a desktop app is me, who simply doesn't like HTML & JavaScript and doesn't want to mess with them; from any other perspective, users would be better off with a web app. – wxd Jun 26 '14 at 15:06
  • then build a web app :P. But think that most of the times there is no such thing as "web app" or "desktop app", you build an application and deliver to our users via web, desktop, mobile or whatever. This things are only the "delivery mechanism" the real app are your classes that model the problem you are solving. Look for information about "delivery mechanism" and hexagonal architectures in this sound good to you. – AlfredoCasado Jun 26 '14 at 20:08

The simplest way would be to implement it using web technologies (eg HTML controls) so that it can be displayed as a web page easily, and then create a desktop app that uses the same html pages only wrapped as a 'executable'.

To create a desktop application you can either view the web page in an embedded browser in an application that exists solely to show the browser in a window, or you can use something like Microsoft's HTA system that presents web pages as desktop-style windows.

The only other alternative is Wt. This is a system that takes a Qt based GUI application and rewrites the drawing mechanism from the usual desktop controls into html controls on a web page. Its pretty cool considering most applications go the other way round. IIRC its very transparent in that you only need to change a line or two of your original code. Qt is not java though, so I'm only pointing it out for completeness, its still pretty cool though :)


MVC is a good pattern for this, but its the V part "View" that isn't reusable from platform to platform.

The code for modifying the document of a webpage on the clientside without postback is javascript, that is non-negotiable.

The code for modifying controls in a native/jvm form application for example, is not javascript.

So for the presentation part the answer is no, not really. Not for traditional webpage and native/java forms.

The MVC pattern though can make most of your real code reusable, with only the display and view interaction needing to be platform specific.


It's possible through RAP with a single code base to develop a Web application which can be also installed as a Desktop application. Here is the link - http://eclipse.org/rap/

  • would you mind explaining more on what it does and why do you recommend it as answering the question asked? "Link-only answers" are not quite welcome at Stack Exchange – gnat Jun 23 '14 at 13:18
  • I guess Sunil meant that Eclipse RAP is an RIA platform that essentially supports SWT API; so theoretically, it is possible to "convert" an SWT desktop application into a RAP web application. For my purposes, it seems to be an overkill, but in general, it should deserve some attention of future readers with an idea similar to mine. – wxd Jun 26 '14 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.