Over the last few months I’ve been reading several books about Groovy, Spring, Maven, Hibernate and more. I’ve stated before on this blog that I’m moving towards implementing my application’s model in Groovy and using ColdFusion for the presentation tier for HTML applications or Spring’s BlazeDS integration for Flex applications. And now, with those few months of experience under my belt I can authoritatively say that Enterprise Java is a royal pain.
You see, I actually understand Java just fine. I can read the language and, to me, it’s fairly clear. But, as with my German, I’m much better at reading it than speaking it. The reason isn’t that I can’t write the syntax, but that the supporting technologies are so amorphous and decentralized that they can simply be very difficult to learn. Beyond that, they’re often created with extreme flexibility in mind and that means more complexity.
As an example, I’ve recently been working to create a Java (Groovy, really) based web service. This is a whole world of difference from how you’d do it in ColdFusion. I had already decided to use Spring to configure my application’s model and what I wanted to do was expose a service remotely using a specific WSDL. Spring doesn’t include a way to remotely expose services as a SOAP web service (though a dozen other RMI techniques are supported). While researching this I came across a project called Xfire which provides that functionality for Spring. Now, Xfire has a metric ton of dependencies (seriously, check it out here). And, in the interest of flexibility, Xfire allows you to choose from one of many Stax implementations, whatever that is.
So, just to be clear, there are many ways you can remotely expose services using Spring. And, within a particular option there are many choices for Stax implementations. Oh, and I forgot that there are at least two ways to configure Xfire. Oh, and if you don’t want to use Xfire you could use something like Apache Axis. To ask a rhetorical question, how does a newbie have any hope of making a good choice? It seems that only answer is through trial and error.
The cool thing about this is that after a few days of work I was able to expose a Spring configured service via Xfire and it worked great. That is until I did something it didn’t like and I started getting Null Pointer Errors. So, I decided to throw out Xfire and try Axis. The thing is, I’d lost track of the dependencies in my application. I already had maybe 30 jars that my application depending on just for this one service (not counting the Jboss server and everything it requires). I didn’t know what to throw out any more!
That prompted me to do some research on Maven, which is in some respects is an alternative to Ant. I’m not going to get into a description of how Maven differs from Ant, but I will say that it’s a build tool that automatically manages your dependencies for you. The idea being that rather than downloading bazillion jars manually, you simply write some XML that says your application depends on Spring and Xfire and Maven will then download everything for you, along with each dependency’s dependencies.
So, I spent several days reading up on Maven. The thing about Maven is that it wants you to organize your project in a specific manner. For example, there are certain folders by convention that you write your source code in and it builds to specific target directories, again, by convention. This makes using Eclipse a bit more challenging because Eclipse wants you to sort your directories the way it expects. And, when you start adding in features like the Groovy Feature plugin things start really getting cumbersome.
When using Maven with Eclipse you’ll need to use the m2Eclipse plugin (which depends on two other plugins!). Within Eclipse then you’ll need to use m2Eclipse to create a new project. As a part of that process you specify that you want to create a Groovy project. This works like a charm and you can then use the IDE to create new Groovy classes and tests. But, if you want to use any of the built in features of the IDE to run unit tests then you also have to configure the Groovy feature and get that working. I spent, again, a couple days getting this worked out. As it was, I had Maven configured to build a Groovy project, and when I’d write unit tests Maven would run them just fine. However, if, within the IDE, I were to try to run a test via the Groovy plugin I’d get an error about how it couldn’t find my class.
Through trial and error I have learned that you can run Eclipse from a console. If you do this then the console will output all sorts of logging information. When I was having this last problem I started Eclipse from the command line and looked to see what it was outputting when I tried to run my unit test. It took some reading, but eventually I realized that the IDE was trying to use groovy 1.5.7 while Maven was using Groovy 1.6. As a result, when my code was compiled it depended on Groovy 1.6 and the Unit test was expecting 1.5.7 and wouldn’t run 1.6 code. It makes lots of sense, but figuring this out was a royal pain!
Once I knew that, I was able to upgrade my Eclipse plugin to be the same version as Maven was using and suddenly my project would not only build, but I could manually run unit tests.
I’m not sure if I have a moral in this blog entry or if I’m just ranting. However, I can say that when things start working and can I get that flexibility working in my favor I love it. But, when things are not working and the error messages are less than helpful it can be extremely frustrating. So, be thankful for ColdFusion. But also, don’t give up on these other technologies. They do actually work, but they’re hard to learn all at once.
Comments on: "Getting Started With Enterprise Java is One Huge Pain" (13)
Doug, it seems you have a few basic problems:
1) Technical – such as exposing SOAP based Web Services
2) Configuration (or, trying to settle on a particular configuration option, given that there are many available)
3) Integration (with Eclipse, for example)
I think I’d need to know why the several layers of technology when you state you will be using ColdFusion in some regard, and that has the answers to the problems you presented in this blog post.
Now, CF is limited, you are “boxed in” to a degree by what it offers, but if you are “getting started” with Java in the enterprise, isn’t that a good place to start?
Maybe I missed the beginning of the conversation on your technology choices.
Cheers,
David
LikeLike
@David – Yea, I’m actually making progress on this. I’m not actually asking for help here, so much as saying getting started is hard.
My ultimate goal here is to make it really simple to write a Groovy+CF hybrid application, but there are so many things involved in this that the learning curve is steep.
Again, I’m not really asking for help… I’m more stream of thought writing, which may not be the best idea I’ve ever had. 🙂
LikeLike
Ah, ok, I was off on your ultimate goal – that makes sense then.
Cheers,
David
LikeLike
Did you check out the “Spring Web Services Project” http://static.springframework.org/spring-ws/sites/1.5/ ?
This allows you to build “contract-first web services” where you write the WSDL first and then write the implementation (which is very nice if you’re building a public API and you want the freedom to change your service layer after you’ve published the WSDL). The other nice feature is that there are no nasty dependencies on XFire or Axis jars.
The Web Service Project’s not included the core Spring distribution, but it’s fairly mainstream.
LikeLike
@Graeme – I have looked at it, but in my readings I couldn’t find a way to expose a Soap web service with Spring WS. OTOH, I openly confess that I’m new to this stuff.
LikeLike
I’ve been doing a bit of the same, though probably less extensively than you (hven’t delved in web services) and I have to concur, the learning curve is steep and there are all kinds of weird behaviors when trying to mix all the technologies (java, groovy, and CF). Yes, it’s all java, but it actually ends up being a lot more complicated. Like yourself, I’m hoping I’ll eventually come up with a development environment that’s more powerful and that I feel more productive in. Will probably take a while… Anyway, just wanted to let you know you’re not the only one! Good luck.
LikeLike
Hey Doug,
I feel your pain. Some recommendations – for what they’re worth.
(i) Use Grails when you can – it wires everything together and gets you started out of the box. Unless you need to optimize for performance, it pays for itself even if you just want to do a web service because it handles all of the dependencies and will even build your war files.
(ii) IntelliJ. It’s $250 if you don’t need to pass it around to other devs in the company and life is too short for weak IDEs. Eclipse rocks – but not for groovy or grails. At least give the 30 day trial a shot.
(iii) I use maven for anything java like. Not had any problems with IntelliJ when doing that
(iv) If you *really* want to do groovy, drop CF from the front end and use grails end to end.
(v) If you’re committed to CFML, consider using ColdBox. Get with Luis and check out the new Groovy loader they’ve got in. From what I’ve heard, you can use groovy beans with jpa annotations for persistence and if you design the app nicely you *might* even refactor to use the CF or Railo hibernate integration when it comes out. This is the way I’m going on a fairly big project that I’m starting on and it’s looking very promising.
Good luck with the craziness, see you at cf.o()!
LikeLike
Doug,
Yeah, really makes you appreciate ColdFusion, doesn’t it? It hit me when I got to the point where I had to choose a connection pooling implementation for Hibernate. Que? Don’t the leprechauns just deal with that for me? But the other side of the coin is, there are at least two production-ready enterprise grade connection pools available for the very reasonable price of zilch. It’s like being beaten over the head with gold bars – it hurts, but every now and then they drop one…
LikeLike
Jamie, I think you really hit it on the head (pun intended)… In all seriousness, there are upper limits of what can be accomplished in CF. And there are very large groups of people producing open source, enterprise class, projects for Java. We just don’t have enough people in the CF community to keep up.
LikeLike
I only have intermediate skills at Java and know little about Groovy, so bear with me as I ask this fundamental question: What would be wrong with using ColdFusion facades for the web services, which just instantiate your Groovy/Java code to do the heavy lifting? Wouldn’t you still be leveraging the power of Groovy/Java but benefit from how easy CF makes web services?
I’m sure there’s some performance hit or something with that paradigm, otherwise you probably would already be doing that..
LikeLike
Joshua – That’s a very valid question. In my case I really do have a valid business reason. There’s a third party system I’m trying to integrate with. However, they require that you implement a web service that satisfies their WSDL. Unfortunately, I can’t create a web service in CF which works for this.
In the past I wrote a cfm which manually parsed the SOAP request, but it was a troublesome hack. I’m trying to get away from that while creating a system that can work naively with Java and easily with CF and Railo (and maybe even BD), and also, if possible exposing its features via web service so that any other language could use it.
LikeLike
Ok, that makes sense and I can very much relate to that pain. I had a similar issue with CFHTTP making a POST request, and the 3rd party didn’t like it, so I was stuck with…less preferable solutions.
LikeLike
I just so happened to be looking at the docs for cfcomponent for something completely unrelated, and noticed a “wsdlfile” attribute that lets you provide your own wsdl. I’m not sure if the CFC’s auto-generated wsdl is giving you trouble or the transmissions themselves, but I figured it’s worth throwing out there.
LikeLike