Learning Java Web Stuff

Relearning Java and JSP

Over the last couple of weeks I’ve been relearning Java and JSP and learning about Google’s GWT . I learnt Java when it was first released but I last used it around six years ago and I never used it seriously in a  large project.

I’m now up to speed on new stuff in the Java language, such as annotation, generics, and enumerated types, some of which I really missed not having before. A newer edition of Bruce Eckel’s Thinking In Java was great for that. I’ve always  liked how he includes comparisons to other programming languages (C++, Python, C#) and is unafraid to criticize the API that he’s demonstrating, though I wonder how interesting that is to other people.

For JSP I tried a different style of book: Head First Servlets and JSP. It’s full of clip art and silly captioned kung-fu photos and cartoons but that really did help me to keep reading. I’m only slightly ashamed.

No, I’m not going to do less C and C++. I love C++. It’s just not what’s used for web development.

Learning GWT

Of course any web site these days must use AJAX to provide a more interactive page, exchanging data with the server and updating the page without doing a whole page refresh. I’d like to avoid writing or maintaining Javascript if at all possible, so Google Web Toolkit seems like a good choice. Bizarrely, it generates javascript from Java, and it even has (imperfect) Javascript implementations of some of the standard Java library. It’s weird but it seems to work. I believe it’s used for gmail and Google Maps.

I’m using the GWT in Action book, though the online GWT documentation seems fine, and the self-hosting runnable examples are really helpful.

Maven

This also included learning about the maven and ant build/configuration tools. maven feels roughly equivalent to autotools plus pkg-config, with ant being roughly equivalent to make. As far as I can tell maven is the in thing.

So far maven is working out well for me, though all the XML to use the necessary plugins feels like voodoo and it has taken me days to get some plugins working, for instance to build WAR files to deploy to tomcat, and to use JNI. The incredibly obscure error messages don’t help and when it does what I want I am thankful but never quite sure how it knew what I wanted.

I also feel weird about using plugins from sites that I’ve never heard of. Without being familiar with the history and community, I have no way to know what is the official best plugin to solve particular problems.

Eclipse Pain Again

This is an opportunity to give Eclipse another chance. After all, it’s meant to be wonderful for Java development, right?

But I seem to need various extras to work with common things like JSP and maven, which forces me to use the hateful “Software Updated and Add-ons” feature. The problems with this are numerous:

  • It shows me many similarly but incomprehensibly named add-ons so I don’t know which one I want. It should explicitly tell me exactly what I would expect to see in my Eclipse UI after installing each thing.
  • It sometimes shows me duplicates of add-ons, just in slightly differently-named directories. What do I choose?
  • It sometimes shows me countless minor versions of the same add-on, instead of just showing me the latest one. There’s a checkbox for that in some versions – it should be on by default.
  • It almost always tells me that some dependency (or some version of some dependency, I guess) is missing. If it doesn’t know how to find it then I certainly don’t. Fail.

I managed to install the WebTools add-on in one of my Eclipse installations. But it has a rather hacky MSWindows-centric wizard, which assumes that all of Tomcat is installed in one directory and won’t let me get further until that is true. Of course on Linux distros things are split up between /usr/lib, /usr/etc, etc.  Some helpful Fedora people seem enthuasiastic about fixing it.

Anyway I generally dislike the idea that I must use a particular project wizard for things that are orthogonal. I shouldn’t be forced to choose between my programming language, my build system, or some of my dependencies. They should be independently interchangable. I suspect that I’d be happy with Eclipse just as an editor, using the command-line with my hand-edited build files, but I never seem to get that far. Eclipse should make it more obvious how to do that because it’s currently a rather hidden feature in some of the new-project wizards.

Note that I’ve tried standard Eclipse in Ubuntu Intrepid (Even Jaunty only has Eclipse 3.2), Eclipse 3.4 in Jaunty (by downloading it and running it from a directory, which works surprisingly well), and “Fedora Eclipse” 3.4  in Fedora 10 in a vmware image.

I’m not ready to give up just yet. I’ll take another run at using Eclipse just as a simple editor, trying not to use any special add-ons. But my patience surprised me.

Online Glom

This isn’t just to refresh these skills and prove to myself that I can still learn. I plan to use this to create a web UI for Glom. My plan is roughly:

  • Use JSP for the standard static parts of the page. This gives me easy authentication and session management.
  • Use GWT from within JSP to construct large parts of the page (identified by div tags). This gives me fancy AJAX UI widgets and a way for client-side code to communicate with code on the server without a page refresh.
  • On the server side, use my C++ libglom library via a Java wrapper generated with SWIG. This will at least give me database structure and UI layout details from .glom documents.

Although AJAX allows us to do more than the old submit-form/get-new-page UI of CGI, I am still not looking forward to dealing with the increased use of async coding compared to desktop coding, batching information up to reduce client/server communication, and being restricted to aggregations of serializable/copy-by-value primitive types when doing that.

My initial inept attempts at all this are in my online_glom repository on github. There’s hardly anything to see but there’s probably already plenty to correct.

24 thoughts on “Learning Java Web Stuff

  1. Murray, you should try NetBeans, is a more focused IDE than Eclipse is, and it’s UI/plugins (despite being much less plugins) are better well thought IMHO. For pure Java/JSP development is actually quite nice and I find a better experience with it than I’ve done with NetBeans. I’m still not quite comfortable with it for other kind of development though.

    (And no, I’m not posting this because I work at Sun, I seriosly think that NetBeans has a more pleasant experience for Java development)

  2. I second Alberto, I was using Eclipse every day for more than 3 years and then one day I decided to try NetBeans. I haven’t launched Eclipse since that day. Seriously. As Alberto wrote, the UI is much more better thought, it simply does things as you would like it to do them. One drawback is slower responsiveness of the UI, it is based on Swing and not on native GTK but it is not so bad.

    (I do not work for Sun :-)

  3. Alberto, karol: Thanks, I am trying NetBeans in Ubuntu now. It seems to have had more love from Ubuntu than Eclipse. It does look ugly (that file chooser dialog is a horror), but it is a little simpler. I really like how simple it is to use a maven project with the maven plugin.

    Like Eclipse, it seems to force these fork-in-the-road decisions between things which are orthogonal. For instance, why can’t I have a web project that is also a maven project? However, the plugin installer is far simpler than the one in Eclipse and actually works.

  4. ReinoutS, I know it’s cowardly but I just don’t want to deal with anything remotely unusual for this. I want a simple life and a robust vastly popular platform.

  5. MurrayC, don’t worry, Wicket is a mature technology with a vibrant community that has graduated to a top-level Apache project last year. You will find Netbeans plugins readily available and it works nicely with Maven. Check out the article I linked to, you won’t regret it.

  6. “No, I’m not going to do less C and C++. I love C++. It’s just not what’s used for web development.”

    …and Java is? :-) From my vantage point it seems pretty rare to see Java used outside enterprise or, less commonly, client-side development (most of my experience is through the latter in classes). Java’s a decent language, and you can certainly use it for web development, but it’s hardly what comes to mind when someone says “web development” and “programming language” in the same sentence.

  7. I think doing a web UI using java technologies is a good idea. I won’t recommend anyone to do it in PHP/Ruby/etc. or in C++, but that’s because I write java code for living.

    I think you picked the right choice with maven. I’ve been down the road of writing ant files and switched all of my projects to Maven 2. It really rocks compared to ant. If you need some advice feel free to ask.

    I’m not sure if I’d go for JSP. I went through the effort of writing JSP myself and went pretty fast on to JSF. You get many nice features that JSP lacks (the whole MVC stuff). And you really get nice aditional toolkits like RichFaces (which is similar to what gantenbein proposed for GWT).

    It’s a matter of taste and I’m looking forward what you come up with. Feel free to ask me for help with strange Java/JSP/Eclipse/Maven errors. I’m glad to help you to avoid mistakes I already made :-)

  8. I use to have much pain when dealing with Java too.
    Specially for us, who develop through such organized and clean environments, libraries etc, like, GObject, GNOME.
    Anyway, I hope you find some light at the end of tunnel :)

    Happy Hacking !

  9. I think your summaries of the build tools miss the mark a bit. You’re pretty much right about Ant – it’s similar to Make, but centered exclusively on tasks – the concepts are more “‘run tests’ depend on ‘compile'”, rather than “file hello.co depends on file hello.c”.

    Maven is a little more complicated though – there’s not really a parallel in the C coding world that I know of. At it’s core though, it’s a tool for managing artifacts (most commonly jar files), from input files and dependencies. As such, it’s a bit of pkg-config, a bit of libtool, and all sorts of other pieces of the autotools stack – bits of package management too, for that matter, since it downloads dependencies from repositories instead of relying on someone providing them. I’ve found it quite difficult to get used to the artifact-centric approach, but I’m getting to appreciate the tool now…

  10. I developed a lot of webbased applications like Glom using PHP and Java.
    Today I always prefer Java, because the biggest advantage of Java is a strictly typed language plus a compiler.
    At the moment I’m using GWT with plain rpc servlets and ExtGWT.
    ExtGWT is a eyecandy widget library with features/widgets like Grids, EditableGrids and FormBindings/GridBindings for
    automatically syncing your Models/Pojos with a form and vice versa.

  11. Hello,
    I do Java programming for living. I can tell you some ideas.
    First I do use Eclipse IDE, but I know it uses a different approach to how to use an IDE and if you try to use it just like a text editor for Java you will not see the point for using it. Maybe you will not even see why use it. If you don’t want to choose your plugins them try EasyEclipse. They are have Eclipse configured for you.

    For Web development, I would not use JSP. It is strange and limited and…weird. I do choose Wicket. Give it a try.

    Good luck.

  12. Like other people said, Netbeans is great for doing java development. However, I would recommend to install the latest version. Unlike Eclipse, is one install script and easy to install.

  13. ReinoutS, Thanks, I spent some time looking at the wicket website, but it doesn’t get to the point and I still don’t really understand what it offers me. I’m ready to believe that I’ll want it after spending more time with JSP, but at the moment it seems that I’ll need that experience to understand that.

    egore, JSF seems to be a way to put AJAX widgets on the web page instead of just HTML via JSP (though whether AJAX is actually used seems to be annoyingly undefined by the specification). I would need some convincing that its use of AJAX is as capable, mature, and extendable as GWT, but I can’t find good information out there.

  14. I’d suggest avoiding JSP and JSF – go for a simple templating mechanism like freemarker for pages, or gwt for widget like stuff

  15. Maven offers the task “mvn eclipse:eclipse” – creates an eclipse project from the pom.xml with all dependencies resolved, ready to be imported in the eclipse workbench. Allows you to use eclipse as a java editor, just what its good for.

  16. I’ll also suggest not using JSP. If you’re using GWT, then JSP is not necessary.

    Also, few professional Java programmers use Eclipse or NetBeans. Get a copy of IntelliJ. It pays for itself in saved time after about one day of development.

  17. Hey murray,

    I did some JSP work at school (3 years ago), back then I liked it but now I don’t like web-dev any more…its a pain in the a**.

    A couple of weeks ago I was part of a bigger project at MUC (Munich airport), organized by the university. We’ve written a backend server with java and some other guys did the GUI work with objective c and cocoa for MAC. There we’ve used Maven for the continuous build. What I’ve learned there: don’t use subclipse, use command line svn or something else instead; don’t use the maven eclipse plugin to build, just to resolve the dep’s, use mvn in the terminal instead.

    Cheers
    Felix

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>