Author Archive
24ways
by Chris Wash on Dec.01, 2008, under Meta/Blog
I can’t believe it’s already December! I came across 24ways last year and thought it was a neat concept: an ‘advent calendar for web geeks’ – take a look! They had a pretty good variety last year and I’m expecting some good things this year.
Must Haves/References For Modern Java EE Developers
by Chris Wash on Nov.28, 2008, under JBoss Seam, Java, Software Engineering
I’ve been doing a lot of reading lately and have been meaning to plug some of my favorite reads, and one of the things that I’ve been trying to read with an eye toward is for converting those that have been stuck on “behind-the-curve” projects to the new way of thinking and doing things. As such, and just in time for the weekend, I’ve compiled a list of my favorites with an eye to the “movers and shakers” that have driven innovation in the Enterprise Java world recently. Note that even though some of these links are specific to certain frameworks/technologies, there is a common thread throughout most of these that have a bigger focus on the best way to solve problems using Java 5/EE 5 constructs and concepts.
A book that should be on any Java developer’s shelf is Effective Java (2nd Edition). Make sure you get the second edition, for all of the Java 5 changes. This talk by Joshua should whet your appetite. (His talk on good API design is also very good.) You should also take a look at Bob Lee’s talk on Guice. Guice’s philosophy and focus on typesafety has spilled over into Web Beans (and newer versions of Seam) and its annotation based approach has heavily influenced newer Spring features. I especially like his points on type safety around the 11-minute mark. The walkthrough at the end of the talk from “old way” to “new way” is great for people who haven’t really gotten away from Factories, Delegates, and Service Locators yet.
The Guice video mentions that a common thread in modern Java frameworks is a focus on testability. Testing is a very important concept that nearly all new frameworks have embraced, but you still need know-how to be successful with testing. I’ve come across some great books recently in the automated (developer) testing arena. I’ve found the most thorough book on the topic out there is Lasse Koskela’s Test Driven. The ideas and topics discussed in the book are really language independent, and work equally well with other languages. To cut your teeth on TestNG, which the Seam documentation turned me onto, I recommend the TestNG developers’ book Next Generation Java Testing: TestNG and Advanced Concepts
. Cedric Beust, also the author of EJBGen, and Hani Suleiman, author of the Bile Blog, produced a book that was a suprisingly good read. It’s packed with a lot of knowledge and some interesting takes on EE concepts. Newer versions of JUnit also include many of these features and concepts, so you’ll get the underpinnings of these concepts in this book. This video gives you a basis to TestNG’s approach.
As one of the growing number of developers who have an application in the Seam In Production page, there are a few Seam resources I have to share. Even if you don’t get into Seam, it should be on your radar because a lot of the core concepts around conversations have evolved into Web Beans, and are found other frameworks like Apache Orchestra and Spring WebFlow. Pete Muir did a Webcast that’s a great introduction to Seam 2.
Author of one of my favorite Seam blogs, Jacob Orshalick, has created a DZone RefCard for Seam 2.1 Core. It’s right off the presses, being published this week, but is a great quick-capsule review of what Seam can do for you, and nice to have on your desk if you’re writing Seam. If you need more in-depth descriptions of what’s on the RefCard, Jacob also coauthored the latest edition of the great Seam reference Seam Framework: Experience the Evolution of Java EE.
Dan Allen’s Seam in Action is another excellent resource. Of course, the awesome Seam Docs and Forums always come in handy. You should also RSS in.relation.to – the Hibernate/Seam developers’ group blog.
I know I’m leaving some great things out. What resources do you think someone who is used to J2EE should take a look at to get them “up to speed” with the state of the art?
Java 6 and Maven 2.0.9 on Leopard
by Chris Wash on Nov.19, 2008, under Java
Trying to run through a screencast I’m putting together after upgrading to Leopard, I noticed Maven giving me a strange error when trying to run archetype:generate and realized that Leopard includes its own version of Maven (and Ant) out of the box. The problem is that it’s version 2.0.6, which doesn’t have support for this feature. I then set about trying to upgrade Maven (and in the process, Java) and here is what I uncovered.
First of all, I screwed myself over a bit by customizing my /etc/profile under Tiger; there were changes to this file that came in with Leopard but I can’t see where the updater tried to merge them in at all. There are changes in Leopard to how paths are configured using a script called /etc/path_helper, but I don’t have any of that getting executed. It took me a while to figure out this was the reason my .profile, .bash_profile, etc weren’t getting source’d properly. What I did was pull out all of my updates to /etc/profile and just add in the following:
source ~/.profile
So at least now I have my .profile getting loaded properly. I’d still be interested to see someone’s /etc/profile that works out of the box with the call to /etc/path_helper, but this is all beside the point.
Applying the Java update was painless – it worked fine through the Apple Software Update utility. You can download it here manually if you need to.
Next, you’ll probably notice that Java 6 isn’t enabled by default. This blog will show you how to switch over to 6 using the Java Preferences utility. There is a flaw in the ointment, though – for some reason it appears that it doesn’t switch over all of the symlinks properly. Maven’s startup script gets confused by this in a few steps. You can read more about it in this message (some JIRA comments) from their mailing list. The workaround is to just point your JAVA_HOME directly to the 1.6/Home directory.
You can install the newer version of Maven at this point. I saw this post detailing the instructions, but it was what I expected. Just download the latest version and extract it to where you keep these kinds of things. Then you just have to update your .profile (or .bash_profile) to set up some environmental variables for you. Here’s what I included in my ~/.profile:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
export M2_HOME=/Java/apache-maven-2.0.9
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
You’ll need to do source ~/.profile or exit out of your terminal and open it up again for the changes to take effect. Once you do you can test to make sure you’re seeing the right version of Maven:
cwash:~ chris$ which mvn
/Java/apache-maven-2.0.9/bin/mvn
You can also check this by doing:
cwash:~ chris$ mvn -v
Maven version: 2.0.9
Java version: 1.6.0_07
OS name: “mac os x” version: “10.5.5″ arch: “x86_64″ Family: “mac”
I guess we can chalk this one up to kicking the tires on Leopard. Hope this makes the process a little less painless for someone else!
Axis2 client using ADB - runtime dependencies
by Chris Wash on Sep.10, 2008, under Java
I couldn’t find any definitive answer to this question, so here’s what I found, just incase anyone else needs this little nugget of information: the runtime dependencies for an Axis2 client that uses Axis Data Binding (ADB):
activation.jar
axiom-api.jar
axiom-dom.jar
axiom-impl.jar
axis2-java2wsdl.jar
axis2-jaxws.jar
axis2-jaxws-api.jar
axis2-metadata.jar
axis2-saaj.jar
axis2-saaj-api.jar
backport-util-concurrent.jar
commons-codec.jar
commons-fileupload.jar
commons-httpclient.jar
neethi.jar
wsdl4j.jar
wstx-asl.jar
xml-resolver.jar
xmlbeans.jar
It’s long, I know - but not as long as what you find in $AXIS2_HOME/lib!
Weblogic 9.2 + Seam : Victory is Mine!
by Chris Wash on Aug.21, 2008, under JBoss Seam
After fighting with WebLogic 9.2 for a while, I was able to get a seam-gen’d app running.
You’re relegated to using JPA/Hibernate because of an outstanding bug BEA and Sun seem to be both pointing fingers at each other over, but it’s not a big deal. At least for now, all of the persistence in this app is going to be offloaded to services.
I’ll work on writing this up more formally, but here was a running list of issues I had to deal with. If you need more information, let me know. I apologize that this is kind of rough, but it’s better than nothing.
- Follow steps outlined in reference guide. (http://docs.jboss.com/seam/2.0.2.SP1/reference/en-US/html_single/#weblogic)
- Change the build.xml’s jboss.home’s to bea.home’s, and redefine them like so:
<property name="deploy.dir" value="${bea.domain.dir}/autodeploy" /> <property name="jboss.deploy.dir" value="${jboss.home}/server/default/deploy" /> - Remove the library-ref from weblogic.xml (that you put in following the ref guide).
- Remove the Namespace, Schema, and Version definitions for the web-app tag in web.xml - there’s a problem trying to add version 2.5… (https://jira.jboss.org/jira/browse/JBSEAM-2247)
- Remove JSF/MyFaces deployments from WL domain if there are any (JSF 1.1 libraries conflicting with 1.2)
- Add jsf-api.jar, jsf-impl.jar, commons-collections.jar, persistence-api.jar, el-api.jar, el-ri.jar (needed to pull out of seam fisheye) to deployed-jars.list. You should be seeing Seam trying to start up at this point, IOW, you’re in “whack-a-jar” mode.
One other funky thing — and I’m not sure what error exactly was causing this (probably related to the interceptors and JSF problems causing the deployment to suspend) but WL was causing some locks to occur that I had to clear out of my domain/server/tmp/* and basically “clean” everything out. It was quite annoying, but things seem to be better now.
How I Escape the “Reuse Trap”
by Chris Wash on Aug.02, 2008, under Software Engineering
If you’ve checked out my blogroll, you’ll notice I have a link to Basil Vandegriend’s “Professional Software Development” blog. I like a lot of the articles he has written and to a large extent the subject matter I envision for this blog frequently crisscrosses with Basil’s.
While I was reading “The Reuse Trap In Software Design” I found myself thinking,”Me too! Me too!” like a giddy kid on the playground that’s found a new pal with a mutual interest in “pet snakes and/or tarantulas.” As with many of the problems Basil writes about in his blog, I experienced the same problem, investigated it and found the same root causes, and came to many of the same conclusions as those outlined. He describes the “reuse trap” as:
…[A] term I coined to describe the situation when one becomes stuck trying to design new functionality while simultaneously attempting to reuse existing code that needs some modifications.
He then goes on to describe why it’s a tough problem for n00bs and outlines a strategy he uses to get out of the trap–one that’s best described as a two-step process: copy-paste to reuse/refactoring to remove duplication. I encourage you to read his article if you’re not familiar with the terms, or how this strategy can solve the problem described above.
My preferred technique for mitigating the problems involved isn’t copy-paste reuse/refactoring; it’s stubbing the calls to the code-to-be-reused (C2BR) that needs modification. If I can fake out the behavior I need, it lets me focus on the nature of the dependency that exists between the two objects/components. When I go to modify the C2BR, my inputs and outputs (or other consequences that occur as a result of a call to the C2BR) translate directly into a test that I can use to drive the changes I make to that code. It also ensures that the coupling that exists between the objects is loose and legit.
The only thing to watch out for is that care must be taken to then remove the (small) duplication of the stubbed out inputs/outputs and actually wire the two pieces together when finished with the reused code. I usually do that by throwing a TODO:WIRE marker in when I stub something.
I’ve found this is the approach I take more often, though I do take the copy-paste reuse/refactoring route from time to time. This stub/rewire approach is a bit more advanced, but it’s how I envisioned solving the “reuse trap” when, as Basil puts it, “I became aware of it” and all that it entailed.
Do you ever come across this problem? How do you get out of this “trap” or avoid being caught up in it in the first place?
New Apple Wireless Keyboard
by Chris Wash on Aug.01, 2008, under Meta/Blog
On Tim Bray’s recommendation, I just picked up a new Apple Wireless Keyboard:
So far, it seems like a good choice. As mentioned in Tim’s post, I notice my typing speed has dramatically increased immediately, when compared to the built in keyboard, or the stock Dell keyboards I’ve been typing on when not at my Mac recently.
I didn’t think the num pad warranted the extra space it’ll take up when I carry it around with me. The super big command key doesn’t concern me quite as much, because I’ve gotten used to slipping my left thumb down to hit it from hovering over the spacebar, and it’s easier/more natural to do that on this keyboard compared to the one built into the MBP.
And this all goes without saying that the wireless features are a big plus. Whenever you sit down to do something, having to plug in an extra wire is nothing short of a pain in the ass (not to mention taking up valuable port space on my precious laptop).
So far I’m pretty happy with the purchase. If my opinion changes, I’ll let you know, but the spot judgement is that it’s exactly what I was expecting.
Help the Good Guys
by Chris Wash on Jul.31, 2008, under Meta/Blog
I think it’s important to support and give back to products and efforts that are high quality and enhance your productivity, happiness, or everyday life. A List Apart, a web published magazine “for people who make websites” was the first feed I remember adding to my feed reader. It definitely falls into this “need to give back” category for me. Their articles have a web design/development slant, and are written in a consistent, succinct, repeatable fashion. It’s a successful site, and I applaud its efforts.
If you didn’t know about ALA, well now you know. If you do know about them, give something back by participating in their survey.
Pimp My Build
by Chris Wash on Jul.21, 2008, under Software Engineering
In terms of the sheer number of moving parts, extravagance, and complexity, the build-tool landscape is one of bells and whistles that can be a little tough to stay on top of. There are a few important pieces of a robust and valuable build, no matter what tools you use to achieve it, and by breaking the build into modules or categories, we can make a little bit of sense out of the chaos.
In our vast build-tool landscape, there tend to be some zealous cults out there, entrenched deeply in their own camps and unwilling to venture out to explore what the rest of the landscape has to offer. Thus, there have been some religious-like differences of opinion about which build tools are better and why. Sadly you run across these types of biases all too often, which only pollutes the landscape and makes it more difficult to wrap your head the most basic questions underlying all tools:
- What does it accomplish?
- When is it (or isn’t it) right for the job?
- How do I use it effectively and efficiently?
With a pragmatic view, we can try to cut through a lot of the BS and figure out if a tool is worth its weight in:
- dependencies/design complexity.
- ease of use/interface complexity.
- architectural decisions/compromises that it brings to the table.
Does the tool get us to the goal of a single button build/deploy? If the answer is yes, I’ll welcome it with open arms. Does it add me a form of feedback or some kind of statistic that could be a kind of gauge on a dashboard? Then I may be interested in it, but it’s not nearly as vital.
Here’s an outline of what I typically look to include in a project’s build before I am satisfied:
- Compile - Obviously your build script would be for naught if you didn’t include this piece. There’s also something to be said about some dynamic/interpreted languages (that run on the JVM) taking the hit on this step and producing compiled versions. The argument is akin to compiling your JSPs back in the day.
- Unit test suite - Another one of those no-brainers! You’ll obviously want to integrate your ability to run a single test or test suite from a build tool quickly and easily.
- Test reports - Test reports are an important way of visualizing the health of your project and are usually the first place you’ll go when you see something wrong. A must have.
- Transitive dependency management - This is one of those sticky subjects that people like to argue about religiously. Really the important thing to note here is that a crucial part of keeping your build clean and manageable is figuring out how to represent and resolve transitive dependencies, or second-level dependencies. If your code directly depends on a library, odds are that library has its own run-time dependencies that need to be satisified in order for it to work properly. Since managing the different versions of many different libraries can become tough when you start to look at different “stacks” of software, many people advocate having a tool help you resolve these dependencies so it’s not as daunting a task to get the entire stack to work again when you need to upgrade a single library. Maven and Ivy solve this problem by introducing repositories that will house and dynamically resolve these versioning issues, in much the same manner as yum or apt-get does in the Linux world. A lot of newbs will make the mistake of thinking this type of functionality will let them turn off their brain when it comes to think about their project’s dependencies. They will be sorely mistaken! The point of these to make resolving conflicts in transitive dependencies easier, they do not replace your brain, nor your obligation to know the dependencies in your project and how they fit together!
- Utility ant tasks - the daunting part of learning how to write good builds has a bit to do with how much you know about the ant task landscape. Nearly all libraries have tools that plug into ant, but which ones do you really need to know about? I’ve found a few are quite powerful, particularly replace, uptodate, cvstagdiff (and corresponding svn’s), xmltask and dbdeploy. I think these tools should be looked at when you are trying to figure out how to accomplish something specific, and for that reason, they’re a bit more like “bells and whistles” than anything else. The same goes for the next category, which arguably doesn’t even need to live in your build (but if you’re a team player, it’s a definite nice to have):
- Static analysis - There have been a barage of slick static-analysis tools that have entered the Java landscape recently. A few are FindBugs, PMD, CheckStyle. While most of these tools have plugins that integrate nicely into an IDE, it’s also helpful to have them plugged into your build, too. Just to make sure everyone is following the rules. A few others I’ve seen that focus on cyclomatic complexity, cohesion/coupling are Metrics and JDepend.
What build tools fit into your pimped out script?
New Wave Logging
by Chris Wash on Mar.19, 2008, under JBoss Seam
Tired of messy logging logic cluttering your code with a bunch of if/else statements? Don't let logging cramp your style! The approach Seam takes to logging makes your code pretty again (and other things). What does this mean for you? No more "code guards"!
A nice byproduct of the genius of Seam's design is that many common problems can be solved by using EL as veritable swiss-army knife. We'll look at this through a logging example specifically, though it's just one of many different innovative ways of solving problems using Java5 features and EL as a general approach.
WTF is a code guard?
What goes without saying in most of the discussions regarding logging is that excessive logging can be the largest and most common performance bottleneck in code that meets its functional requirements. Thus, logging APIs introduce the idea of log levels, to ease the burden of excessive logging. Generally, log levels are a configuration setting on a per-environment basis. Development environments will typically log most dependent code at the info level, and cut that up to the debug level for custom code or when things go awry with a piece of dependent code. Testing environments typically log at info while production will often just log at the warn level.
While this is all well and good, we find that for a lot of the logging we do, we typically run across an ugly little flaw in this approach that's produced an equally ugly hack as a work-around. Enter the code guard. From the log4j docs:
Code guards are typically used to guard code that only needs to execute in support of logging, that otherwise introduces undesirable runtime overhead in the general case (logging disabled). Examples are multiple parameters, or expressions (e.g. string + " more") for parameters. Use the guard methods of the form log.is<Priority>() to verify that logging should be performed, before incurring the overhead of the logging method call. Yes, the logging methods will perform the same check, but only after resolving parameters.
What's all this business about resolving parameters? Let's look at an example:
-
// unguarded code
-
log.debug("FOO: " + foo + ", BAR: " + foo.getBar());
-
// guarded code
-
if (log.isDebugEnabled()) {
-
log.debug("FOO: " + foo + ", BAR: " + foo.getBar());
-
}
So, we need this cluttered if/else around only to ensure that our expressions (concats, usually) won't get resolved unless we actually want them to. Why is there no other recourse? The answer isn't surprising – it comes down to the way the API was designed. All log4j logging methods take a single argument -- which made a lot of sense, I suppose when the powers that be first designed logging APIs. They soon realized that in order to use their API, one has to use an expression to resolve all parameters into a single argument prior to calling the method! This is why a code guard is needed.
Java5 introduces a feature that allows for varargs, and taking advantage of this can help us with our ugly little logging problem, e.g.
-
log.debug("FOO: #0, BAR: #1", foo, foo.getBar());
With this approach, our expressions won't get resolved until after we're in debug(), and we can let it do the dirty work inside the method. The first thing that our logging method does is check to see if its level is valid, otherwise it'll fall out immediately. Because the concatenation happens inside the log method, we don't need a code guard to protect us.
This is the approach that Seam takes to logging. Seam's Log interface provides not only a solution that removes the need for code guards, it also allows you to use EL in your log messages (if you're trying to dive into a Seam component...) - e.g.
-
log.debug("FOO: #{foo}, BAR: #{foo.bar}");
Much better. By and large, this is the way you do logging in Seam. Because binding occurs late, you never really run into the problem where you need to even think about using something like a "code guard." Code what you're supposed to; not noise! This is just one of many novel ways to use EL in Seam, and why it really deserves a look as a way to write better code, faster and as a far more productive platform for Java programmers (fed up with JavaSE/EE 1.4) than Rails/Grails.
See the Web Beans Manifesto for much more on this approach.


