Tag Archives: java

Ternary operators in JSP

Every now and then I come across things I haven’t used before but should have been using.  The ternary operator in JSP is one of them.

It makes it so much easier to write out some text based on a conditional without having to put it in a request attribute explicitly or do an if/then conditional with a possible set operation using the JSTL core library.

Example:

${booleanTest ? 'output if true' : 'output if false'}

This came in really handy for adding an additional css class to a div based on a condition in the JSP in this particular case.

Hudson As A Service On Vista

I thought I’d setup a new continuous integration server at home tonight and had heard good things about Hudson lately so I gave it a try.  I downloaded the war and ran it as directed and got it configured pretty quickly to pull my source from my hosted subversion repository.  The build ran fine, my unit tests ran fine, it published my javadoc into the workspace and all was good in the world.  Then I tried to install it as a service on my system which just happens to run Vista (please, no comments regarding Vista).  Crap!  (well, I had worse thoughts but this is a relatively family friendly blog)

According to the docs it should work.  I am running as a user with administrator privileges and so forth.  Apparently creating a service in Vista requires you start the process as administrator (i.e. root).  That requires you to open up explorer, right click on the install batch service and click “run as administrator”.

You’re not done yet.  Then you have to go in and change the user you want the service to run as in the service configuration in the services control panel module.  It will then grant the user run as a service privileges and it will actually allow you to now start it as a service.

I also recommend changing the port it runs on by default since most of you probably run your JBoss or Tomcat instances on 8080 when you’re developing.

Overall I think Hudson is great so far but this is just a little gotcha you should be aware of when running it as a service on Vista.

Spring Annotations, Spring MVC and an interesting bug in 2.5.1

I’ve been doing some work in Spring MVC (Spring v2.5.1) and using annotations to see how simple I can keep my XML configuration (pretty small so far) and while coming across a few interesting gotchas that I’ll be describing in another entry I come across this most maddening problem. If you have a Spring MVC controller defined and it even has an inner class in it, the Spring loader will not find it. It basically ignores it. I had been using inner classes for form beans and validators on some of my controllers and it would just not work. By pulling them out into their own classes, however, everything worked.  That was pretty annoying to say the least.

Here’s the bug: http://jira.springframework.org/browse/SPR-4324

And it is fixed in 2.5.2. So if you’re using annotations in Spring, just go ahead and upgrade. It will save you lots of pain.

The other thing, mind your base packages on annotation scans. I’ll be posting that experience in the next day or so. I’m still slapping my head over that on.

My NetBeans 6 Wishlist

I’ve been using NetBeans 6 for a while now. For the most part I like it. I give it a thumbs up overall and at this point I generally prefer it over Eclipse for general web development.

Here, however, is my wishlist:

1. Give me an easier way to find the implementations of a particular interface in my code.  IDEA makes it easy by having a little icon I click on to see a quick list of what implementations the project is aware of for that interface.  The only way I’ve found so far is to hit alt-shift-f12, then select the interface to see the list of implementations.  Pretty much every developer I know codes to interfaces nowadays so this should seem a pretty reasonable request.

2. TestNG integration.  I’ve got a work-around right now but it sure ain’t pretty if I need to debug a test.

3. Better bracket matching in the JSP editor.  I generally write jspx and tagx files so maybe this is just with the JSP XML editor but the jsp:root end tag never lines up with the start tag.  It’s always indented one column.  It’s just strange.

4. Better completion in the JSP editor.  I wasn’t sure I was going to add this but it seems the editor could be better at completing closing tags for me.  I don’t like it to auto-create the closing tag when I start a tag bug when I start to close the tag it should be a little smarter about this.

5. Cut down on the weird errors and warnings.  In one of my entity classes I have a warning that the project does not contain a persistence unit.  What does that mean?  I’m pretty sure it is getting confused and thinks I am running an EJB3 application (I’m not).  This is most likely due to the fact that I am using EJB3 annotations for defining my data model.

6. A better debugging interface.   The debugging interface is just a royal PITA.  It’s completely clunky to navigate local variables and inspect my way through an object graph.

7. Make it easier to debug a web application.  It just seems non-intuitive with the different logging screens that pop-up or are used when you launch your web app in Tomcat (I haven’t tried Glassfish).  It also seems like it launches my application twice.  I’ve seen Spring start itself twice where as it doesn’t do that when I run outside of NetBeans.  IDEA has this streamlined much more.

Overall I am actually pretty happy with NetBeans but these are just things that cause my some slight pain on a day-to-day basis.

Strange Ant Weirdness

I got a new desktop for home the other day and I was downloading all my development tools and something strange happened. I downloaded Ant 1.7.0 and unzipped it into my Java tools directory, set my ANT_HOME variable and added all this to my PATH and typed “ant” and it couldn’t find it. Weird.

I go to the Ant bin directory and there are only 3 .cmd files in the directory. None of which are the ant.bat file. The checksum on the zip file was fine as well. I check the Ant distribution zip file size and it’s 11,288,363. I figure I’ll just do a sanity check and download it again and the new download is 11,390,509. WTF? I haven’t modified either of the zip files since downloading.

The first download came from the http://apache.mirrors.timporter.net/ mirror. I originally downloaded the file on December 21st. I just downloaded it again and now it’s the same size as the distribution I downloaded earlier tonight that works fine. I’m not sure how a build fails like that and gets mirrored…just strange I guess. At least the problem on timporter.net has already been fixed.

Warning: Shameless plug! I’m still looking to hire some great Java developers. I just found one the other day but still have 3 open reqs (what can I say, we’re growing). If you’re in the San Francisco area, drop me a line. We have an amazing space (http://sfarmory.com) in the Mission district that we just moved into and a great group of people to work with. You also need to be okay working in the adult industry. One of the developers I work with has a great post about the jobs.

A New Gig

I recently took a new job at kink.com (warning: not safe for work) to manage the software development team.  I had managed a software development group in the past but for the last few years I was really more into just building software and staying heads down.  If there’s any constant in the software field, though, it’s that things always change.  The change for me was that I wanted to get back into leading a software group and working more with other groups inside a company.  Just building the software wasn’t enough for me anymore.  I’ll probably write about this more at another time but I’ll just leave it there for now.

One interesting aspect about working at a company like this is that the place has an amazingly positive vibe to it.  People just don’t go and work at companies in this industry unless they want to be here so I think that is one of the things that really contributes to it.

We’re also hiring so send me a resume if you can work in San Francisco, know Java well, work with and like Hibernate (we run it as our EJB3 entity provider) and have some usable XHTML/CSS/JavaScript skills you might be a good fit.  You have to take the quality of your work as a matter of personal pride to do well in this group, also.  We tend to mostly run on Macs and you’ll usually have a 30″ monitor to work on.  I can also pretty much guarantee that we have one of the most unique work environments you’ll ever experience.

Why Maven Drives Me Crazy

Step 1. Create a maven project with war packaging

Step 2. Run mvn eclipse:eclipse

Step 3. Open Eclipse. It’s not a dynamic web project.

Step 4. Yell.

Step 5. Look things up on Google.

Step 6. Try some of the things you find on Google.

Step 7. Yell some more.

Step 8. Create a dynamic web project and configure all your libraries by hand.

Step 9. Run web app on server within Eclipse.

Step 10. Go back to Ant and get things done.

I mean seriously, I can’t believe it’s this hard to take a web project and have the eclipse:eclipse task build out an Eclipse project (Eclipse 3.3) that will deploy into a Server instance to make it easier to run/debug.

I’m sure some people have it running but if it’s not relatively simple or documented more clearly or findable on Google within the first page or two then I’m sure I’m not the only one that has thrown up their arms with Maven and use within Eclipse.

On top of all that, just try learning this thing and using it with a Hibernate based project and having to go out and hunt down all the plug-ins you need to make your project do what you want it to do. Any project that makes me do this much hunting around to get it to do relatively simple things that I can do in Ant really quickly is just not going to succeed. The sad thing is that most of the initial impression problems are solvable but no one that is a Maven fan seems to be doing anything about it. Just take the ten or so most popular open source projects, throw a cookbook style doc out there that tells you how to quickly integrate the plug-ins for those projects and do common tasks and you’ll get people that will spend more time trying to use it. As of now, virtually none of the developers I know will use Maven.

(note:  I wrote this up about a month ago and just got around to publishing it so maybe it’s been fixed, maybe it hasn’t but I’m tired of trying to make it work for other reasons as well)

Spring 2.5 Released

It looks like Spring 2.5 was released today. I’ve already been using the annotations for both service definition and web controller definition to greatly reduce the size of my configuration files. These are a great addition and I’m sure that I’ll be exploring them a lot in the future.

The other area that grabbed my interest was new integration test classes that support TestNG since previously they didn’t really seem to support TestNG with their test framework.