Thursday, March 14, 2013

Goodbye Google Reader

Yesterday, I was browsing my feeds in Google Reader and came upon an article relaying the news that Google Reader will be retired on July 1st.  According to the post on Google's official blog, the service was launched in 2005.  I started using it shortly after launch and have visited the site most days since, so I was pretty disappointed to hear the news.  I knew it was a bad sign when the Reader link disappeared from the prominent section of the Google app bar and moved more than half way down the "More" menu, but I hoped that Google would at least keep it alive as long as it made them more money than it cost to operate.  Perhaps that's no longer true, but I have my doubts.  After a certain point, the service ceased to receive much in the way of UI or feature updates and it's hard to believe it's been a resource hog (the same can't be said of Google Wave).  Although I doubt it will make a difference, I signed a petition on change.org, asking that the service be kept alive.

Rather than waiting around and hoping for its revival, I thought it would be worth exploring alternatives to Reader.  A quick Google search led me to a CNET article discussing five other options and Digg announced today that they'll be building one as well.  My plan is to try out Feedly in Chrome and on my phone and see what I think.  So far, so good, but I'll let you know if my opinion changes.

Wednesday, May 25, 2011

GPars For Beginners Presentation

I'll be giving a presentation titled GPars For Beginners to the Boston Grails Users' Group on Wednesday, May 25 at 7 P.M.  Here's my description of the talk:
The GPars (Groovy Parallel Systems) project provides multiple abstractions for concurrent, parallel programming in Groovy and Java. Rather than dealing directly with threads, synchronization, and locks, or even the java.util.concurrent classes added in Java 5, the project allows you to think in terms of actors, data flows, or composable asynchronous functions (to name a few).
In this talk, I'm planning to cover the basics of GPars, including what it's like to learn to use it. Although I've done a fair amount of concurrent programming, I've just started using GPars. As such, this talk should be suitable for Groovy beginners.
If you're a fan of Groovy and will be in the Boston-area, I hope you'll attend.  If you can't, I'll be posting a link to the slides here when they're ready.

In the presentation, I'll be referring to several resources I found helpful.  Here are links to each of them:
(Sorry if this shows up as an entirely new post.  Blogger seems once again to be acting funky.)

Update: Here are the slides from my talk.  Sadly, I forgot to record the audio to go along with it. Sad smile

Monday, October 4, 2010

Is Xmarks Dying or Not?

Early this year, I made the switch from Google Bookmarks to Xmarks. I've been really happy with Xmarks and have used it to sync the bookmarks and open tabs in Firefox, Chrome, and IE on Windows and Firefox, Chrome, and Safari on Mac OS. They had plans for an Android client which I would have installed the moment it was released. Unfortunately, the company announced on September 27th that they'd be discontinuing the service around the end of this year. You should have seen how much the news deflated me. I'd finally found a way to keep all of my browsers in sync and now the service would be going away! Well, I found out some promising news today. The outpouring of support and the number of disappointed users expressing their willingness to pay for the service has made the company reconsider. If you're an existing customer or even someone who just found out about the service and would be willing to pay at least $10 per year for it, please go and sign the pledge at PledgeBank! I really hope it reaches their 100,000 signature threshold.

Update: Xmarks was acquired by LastPass, a company that provides a password management service. You can continue to use each service for free, pay $12/year for each of the premium services separately, or do what I did and sign up for the combination for $20/year.  What a nice outcome! :)

Sunday, April 25, 2010

Technical Research Topics

As you can probably guess from reading this blog, I'm the sort of person that's constantly researching new technologies, often to the point where I move on from a given topic before I've given it the time and attention it deserves.  The point of this post is to both mention what I'm doing to make my attention less transient and to discuss some of the technologies I've decided to focus on.

How am I trying to keep my research interests under control?  Composing a list.  I created a Google spreadsheet and started entering my professional interests.  That probably sounds rather unexciting, but for the first time in a while, I had a concrete list I could look over and evaluate.  The first thing I noticed was that it was long, far too long.  There was no practical way to work on all of the items in the short term.  The natural next step was to sort the list into a rough priority order.  It was hard to push items down ("Ooh, I bet that would be fun!"), but there are only so many things a person can do.

Here's a subset of the list, not necessarily in priority order (I'm still trying to figure out how much I care about the technologies being relevant to my day-to-day work):

  • Git is the distributed/decentralized source control system that Linus Torvalds put together in 2005 to manage the source for the Linux kernel.  It took me a while to grok the notion of distributed source control (I'm not alone), but once I did, I became convinced that it could lead to great productivity gains.  Rather than trying to convince you of this directly, I refer you to the site Why Git is Better Than X, the Getting Started with Git DZone RefCard and Git 101 screencast by Matthew McCullough (registration required), and GitHub.  If you need any extra encouragement, you should know that Git is being used by Grails (and SpringSource generally), Eclipse, and many others that I'm forgetting at the moment.  Learning Git is definitely my top research priority.
  • Static Groovy (most call it Groovy++, but I can't stand that name!) is a project based on the not-yet-released 1.8 version of Groovy that provides annotations allowing developers to designate sections of code (methods or classes) as statically typed.  This brings large performance improvements for many operations, allows some errors to be caught at compile-time rather than run-time, and allows type inferencing similar to what's done in Scala.  I dug into this a bit and ended up changing my mind.  Along with making Groovy run faster, it makes significant semantic changes.  It's not just an addition to the language, it's a whole separate dialect.
  • GPars (formerly GParallelizer) is a project that aims to make it easier to write parallel programs in Groovy.  I originally learned about its smooth support for Fork/Join, but it also enables several other concurrent programming models such as actors, agents, and dataflow concurrency.
  • Gradle is a new build system/language written in Groovy that learns from and improves upon Maven.  Like Maven and Grails, it emphasizes convention over configuration, but unlike Maven, it doesn't become painfully awkward to deal with when you diverge from its conventions.  It uses Apache Ivy to implement its dependency management features.  Speaking of which…
  • Ivy is a sub-project of the long-lived Ant build system and separates management of dependencies from the rest of the build process.  It can be used with Ant or other build systems (see previous).
  • CouchDB is a relatively mature open source document-oriented database that is frequently grouped with other "NoSQL" databases.  It's written in Erlang and stores JSON documents.  It allows you to build views based on Map-Reduce functions written in JavaScript.  I recently signed up for a beta account with Cloudant, a company that provides a hosted version of CouchDB.  As a related alternative, Riak is also definitely worth considering.

Wednesday, March 10, 2010

Finally Bit the Bullet – I'm on Twitter

So, after saying a while ago that I didn't understand Twitter, I've now signed up for an account (softwaregrove).  Why the change of heart?  I thought I'd give it a try to see if it helped me understand the phenomenon.  Truthfully, the thing that finally convinced me is a bit embarrassing – the lure of free (as in beer) software.  See my tweets (I can't believe I just typed that!) to learn more.

Sunday, January 24, 2010

Looking For Part-Time Groovy/Grails Work

As you can see from my LinkedIn profile, I'm an experienced Java developer (starting with 1.0 and 1.1 in the Fall of 1997), who's done some work with Groovy and Grails.  Although I love Java the Platform, I've decided (like many others I know) to gradually shift my emphasis away from Java the Language.  I've decided to focus on Groovy for now, but I can easily imagine adding Scala to my portfolio as well.
So, here's my challenge: I have the good fortune to have long-term Java work for a client that takes up most, but not all of my time.  That means that if I were to take on new Grails (or straight Groovy) work, it would have to be part-time.  That really limits my options.  If I can't find paid part-time work, I'll probably try to contribute to an existing Grails plug-in.  I already author an open source Groovy project, but it's so small that it doesn't really push me to improve my skills.
Any other suggestions?

Update: I found just what I was looking for with Wingu, a startup in stealth mode creating next generation science applications on the web.  Last week, I started working for them a day a week.  I'm looking forward to some Groovy/Grails/Gradle goodness. :)  (reference to mrhaki only slightly intentional)
By the way, if you're looking for something similar and you live in the L.A. area, I just saw a post show up on LinkedIn.  If you're not a member of LinkedIn, here are the details (PDF) on the Extremely Heavy Industries website.  I'm not familiar at all with the company, so make sure to perform your standard due diligence.

Update (Mar. 2, 2010): Things with Wingu didn't work out. :(  I'm back to looking.  This time around I'll try to do a better job of figuring out whether I can perform useful work for the client with the limited number of hours I have available.

Update (Sept. 1, 2015): I took a full-time job with CarGurus.com back in June of 2013 and I've been very happy here. If you're in the Boston area, I highly recommend it as a place to work.

Thursday, January 14, 2010

Prediction for 2010: VMware acquires Terracotta

While at SpringOne2GX back in October, the thought occurred to me that Terracotta would make a really interesting acquisition target for VMware.  VMware has had some pretty amazing virtualization technology for a while, including the ability to migrate live virtual machines between physical boxes, but it has (as far as I know) all been focused on low-level infrastructural magic.  That changed with their acquisition of SpringSource last year, which followed shortly after SpringSource's acquisition of Cloud Foundry.  Now, if you just add Terracotta to the mix, you could make it possible to easily deploy an auto-scaling clustered app to the cloud.  Doesn't that sound interesting?  Add to that the fact that Terracotta has been a sponsor for at least the last two SpringOne conferences in the U.S., SpringSource and Terracotta have already collaborated to build a sample app, and Terracotta brings Ehcache (easy clustered caching) to the table.  Seems like a potent combination to me.

I have no concrete grounds for this prediction beyond the points above, but I wanted to get the idea out there now just in case it actually happens. ;)

Update (May 26, 2010): Unfortunately, with the announcement of SpringSource/VMware's acquisition of Gemstone, my prediction is now unlikely to occur.  Oh, well.  Plenty of others before me have been wrong. ;)

Saturday, January 2, 2010

Problems with NVIDIA GT220 and Windows 7 64-bit

Sorry about the extremely narrow focus of this post, but I wanted to make sure that anyone out there suffering from the same problems as mine knows that they're not alone.

I recently built a computer from parts (more on that another time – I'm not sure how many people would be interested in the details) to use as my primary development machine.  The last time I built a machine was in 1999 or 2000.  A lot has changed in the past ten years.  Fortunately, the assembly/setup process went relatively smoothly, except for problems with one part.  I bought the ASUS-branded version of the NVIDIA GT220 (ENGT220) graphics card from NewEgg.  I'd happily link to their product listing, but that would be rather silly, given that I can't currently recommend it as a purchase.  The card slid nicely into the PCI Express 2.0 x16 slot and my DVI cable attached happily to the appropriate port (this version of the card comes with D-SUB/VGA, DVI, and HDMI ports).  However, when it came time to install Windows 7 64-bit, the problems began.

At first, it was recognized as merely a generic video card – no big surprise, still a bit of a disappointment for a mainstream card that is by no means on the bleeding edge.  My next idea was to download drivers from ASUS's website.  I installed the newest version and rebooted.  Up came the the login screen at full resolution and I thought I was done.  Unfortunately, after I logged in, my screen went totally blank/black.  After much experimenting and many installs/uninstalls, I managed to get the card to work with a slightly older version of the drivers provided by ASUS.  The story would end there, but sadly the problem returned shortly after.  This time, I first did a search on Google for gt220 screen blank, which revealed that others were having similar problems, and not just with the ASUS version.  After reading a blog post and some forum questions and trying several other driver versions, I finally found something promising.  A user on the NVIDIA forums complained that his DVI port had stopped working.  Inspired by that, I tried connecting my monitor via the D-SUB/VGA port instead of DVI.  That worked!  Since then, I've been running for two weeks without a problem.  I can't say I find the solution very satisfying, but at least it worked.

By the way, I'd love to get feedback from other GT220 owners as to whether the solution I described (or something different) works for you.  Please let me know in the comments.

Update (Dec. 10, 2010): I'm a bit embarrassed to admit that I finally gave up and bought a new graphics card with an ATI Radeon HD 5570.  I'd link to the actual card, but I got a great deal on it because it was just about to be discontinued.  So far, it's been great.  It's slightly faster than my GT220 card, consumes less power, has a quieter fan, and (best of all) works on both the D-SUB and DVI ports.  Good luck to everyone who sticks with their GT220!

Monday, December 28, 2009

Handy But Hidden: Collections.newSetFromMap()

I was reminded again today of how much the core Java libraries have grown over the years.  It can be really hard to keep track of all the nice little features that get added in each release.  Today, I was wishing that there was a ConcurrentHashSet class or some other HashSet-style concurrent collection.  Before implementing something myself, I did some searching on Google and found a nice way to solve the problem.  In Java 6 (a.k.a. JDK 1.6), Sun added the utility method Collections.newSetFromMap(), which allows you to pass in an empty backing Map and get out a Set with behavior based on the underlying Map.  So, here is all I needed to do to build a concurrent HashSet:

Set<Observer> observers = Collections.newSetFromMap(new ConcurrentHashMap<Observer, Boolean>());

I also found a bug/enhancement request in Sun's bug database suggesting that this feature should be documented in any core Map for which there is no corresponding Set implementation, such as WeakHashMap and IdentityHashMap.  Given how long I went without knowing the method existed, I wish they'd done it.

Wednesday, December 2, 2009

MorphLabs, the Meta-Cloud Vendor?

Fascinating!  I just got an email from G2iX, the parent company of MorphLabs, inviting me to a webinar (Wed, Dec. 9, 2009 from 11AM - 12PM PST) in which they plan to demonstrate how to "Morph your Data Center into a Cloud Vendor":

Traditional data center and co-location vendors are under tremendous threat in the face of Amazon EC2 and related Web Services, and those providers who’re unable to adapt to some sort of cloud computing model face extinction as competing Infrastructure as a Service products become even more prevalent.

This webinar will demonstrate how the Morph Cloud Computing Platform can help regional data centers transform their business using their existing assets with minimal cost and hardware investments so that they can provide a cutting edge cloud solution to a broader customer base with rates that are more than competitive while still maintaining great profit margin.

For those who are unfamiliar with the company, MorphLabs provides a hosting platform that runs on top of Amazon's EC2 web service.  So, assuming I'm not mistaken, G2iX plans to help data centers other than Amazon's set up the Morph platform to run on their own servers.  My first thought was, "Why would they do that?  Won't this just create competition for MorphLabs?!"  However, once I mulled it over, I realized that if they structure things right, it could be quite beneficial to MorphLabs.  What if these Morph platform deployments simply became new pools of servers to which Morph apps could be deployed?  Viewed that way, it actually sounds quite clever.  I'm almost tempted to attend the webinar, even though it has no direct relevance to me. :)

Thursday, October 1, 2009

Great Star Trek:TOS Quote

My wife and I recently started watching Star Trek: The Original Series episodes via Netflix's Watch Instantly streaming service (they're also available on YouTube Shows).  Although it's a fun show, I still prefer The Next Generation and Deep Space Nine series.  I did, however, come upon a line that made me laugh out loud:

What makes you think you're a man?  You're an overgrown jackrabbit, an elf with a hyperactive thyroid!
Kirk intentionally trying to irritate Spock in This Side of Paradise, Season 1, Episode 24

Saturday, September 19, 2009

JavaScript Date Library Advice?

I've been doing some work recently with the Google Maps API, something I'll try to describe in a future post.  While doing that work, I've realized that I need (or would at least find very handy) a JavaScript library that provides more sophisticated date/time support than the standard JavaScript Date.  Searches have led me to two libraries which look plausible.  Datejs takes the approach of ornamenting the existing Date class with numerous additional functions.  I really like the coding style demonstrated in their tutorial, which is a point in their favor.  In contrast, Fleegix provides a Date class independent from, but interface-compatible with the standard Date (yay for duck-typing!).  They clearly view timezone support as critical for Dates, which I'm very happy to see, since dealing with them and daylight/standard time can be a real pain.  So, from a functional standpoint, both libraries look pretty strong.  I'm concerned that they're not particularly active, neither having any check-ins in 2009, but perhaps it's because they've been around for a while and work well already.  I can't say I found this discussion in the Datejs group very encouraging. :(

Any thoughts?  Anyone out there used either of these libraries or another one they'd recommend?

Update (May 26 2010): I just looked again at Fleegix and have some excellent news!  The projects are now hosted on GitHub and the timezone-js project has some updates from April of this year.  I'll have to give it a closer look soon.

Thursday, September 17, 2009

Subversion – Odd Problems and Funny Solutions

I've been using Subversion and TortoiseSVN since 2005.  They're both great technologies and I'm very happy they exist.  However, I think anyone who's been using them for a while has periodically encountered some weird problems and has had to come up with a few strange (and even funny) solutions.  I certainly have.  In this post, I describe one example.

Earlier this week, a developer I work with saw the following in a TortoiseSVN window when he ran update on a working copy:

Error: Couldn't do property merge 
Error: Unable to make name for 'C:\tempfile'

Not knowing how to proceed, he asked me for help.  We tried my typical first approach: running cleanup via Tortoise on the working copy.  That didn't fix it, so we ran a "Check for modifications" and discovered that there were a few temp files scattered through the directory tree.  We deleted those and tried again.  Still the same message, so on to Google.  I searched for various permutations of the error messages, but was unable to find anything other than code check-in comments for Subversion itself, which appropriately enough uses a Subversion repository.  For some reason, I wish I remember why, we next tried updating just one child directory within the working copy.  It worked!  We tried updating all the other child directories and those worked as well.  So, that suggested that there was something wrong with the Subversion metadata, but only at the top level.  We went into the .svn directory and started browsing through the files.  When we looked at the entries file, we noticed a few lines starting with "incomplete".  I tried moving the entries file out of the .svn directory to a totally different location in the file system, hoping that when we updated or ran another cleanup, the file would simply be recreated.  Unfortunately, with that file missing, the directory was no longer considered by Subversion to be a working copy.  Disappointed, I moved the entries file back into .svn and started thinking about what to do next.  On a whim, the guy I was helping tried updating again and it worked!  Somehow, changing the directory from a valid working copy to an invalid one and back again was enough to fix everything.  Who knew?!

Have any good Subversion/TortoiseSVN troubleshooting stories or troubleshooting tips of your own?  Please leave them in the comments.

Tuesday, August 25, 2009

Curious Concept's Excellent JSON Pretty Formatter and Validator

I just wrote a bit of code using Groovy HTTPBuilder to fetch and parse some JSON content to help answer someone's question on StackOverflow.  When trying to pull some interesting data out of the JSON to display, I realized that it would be much easier for me to understand the structure of the JSON if it were pretty-printed (or pretty-formatted).  When I googled for "JSON pretty format", I found a helpful blog entry pointing me to Curious Concept's JSON Formatter (& Validator).  It's a simple online tool that allows you to paste in either a URL pointing to JSON content or the content itself and display it in either compressed or readable form.  It might not have been very hard to code, but it's extremely useful.  Thanks Curious Concept!

Update: I'm trying out the JSONView Firefox plug-in.  So far it seems to work pretty well.  Even so, I expect I'll continue to use Curious Concept's tool for a while, since I spend a fair amount of time in Chrome.

Friday, August 21, 2009

Merger Madness & One Sample App To Rule Them All

VMware --- SpringSource --- /---G2One
\---CloudFoundry
Terracotta --- Ehcache
Oracle --- Sun


With all the mergers and acquisitions happening in the Java world, I thought I'd suggest a sample app someone could build to bring them all together.

Here it is: a Grails app using an Oracle DB with distributed caching provided by Terracotta and Ehcache, all running in a VMware cloud, with deployment and management handled by CloudFoundry.  I think that covers all the bases.  I have no idea what it will do yet, but let me know if I've missed anything. :)

Note: I actually have a lot of respect for all the technologies and people involved, I'm just feeling a bit overwhelmed with all of the recent consolidation!

Wednesday, August 19, 2009

Interruptible JDBC Statements

I work for a client on a product that makes direct queries against databases via JDBC. A while ago, I added some code so that a user could stop the execution of a series of queries by clicking on a cancel button. Behind the scenes, it interrupts the thread executing the queries. Since that thread checks whether it's been interrupted by calling Thread.currentThread().isInterrupted() before starting to execute each query, no new queries will start once the cancel button was pushed. However, any query that's already started will run to completion before the code discovers that a request to cancel had been made. Recently, my client decided that we should make cancellation more granular and add the ability to stop a query in mid-stream. Looking at the JDBC docs, there's nothing to indicate that any of the relevant methods respond to interrupts (none throw InterruptedExceptions or claim to wrap them in a SQLException), so I had to come up with another way. I settled on an approach where I submit the query as a Callable to an ExecutorService and then block, waiting for the result via Future.get(). If the thread is interrupted while we're waiting, get() throws an InterruptedException, which gives us the chance to call Statement.cancel(). It's pretty simple and works nicely. :)
Here's the code in a somewhat abridged/condensed form (I create the ExecutorService elsewhere using Executors.newCachedThreadPool()):
final String sql = "...<some SQL>...";
final Statement statement = conn.createStatement();
Future<ResultSet> queryFuture =
 execService.submit(new Callable<ResultSet>() {
   @Override
   public ResultSet call() throws Exception {
     statement.execute(sql);
     return statement.getResultSet();
   }
 }
);

ResultSet rs;
try {
 rs = queryFuture.get();
} catch (InterruptedException e) {
 logger.info("Query interrupted - calling Statement.cancel()");
 statement.cancel();
 throw e;
} catch (ExecutionException e) {
 //code to handle or rethrow the exception
}
By the way, if any of the java.util.concurrent classes above are unfamiliar to you, I highly recommend Java Concurrency in Practice by Brian Goetz (et al.). It's an excellent book.

Tuesday, August 18, 2009

Terracotta Acquires Ehcache

Exciting news!  This morning I received a note from Greg Luck via the Ehcache Open Discussion mailing list announcing that the Ehcache project was joining forces with Terracotta and that Greg would be joining the team at Terracotta, Inc.  Since there's been a Terracotta Integration Module for Ehcache for a while, I don't foresee any instant improvements with regard to integration between the two technologies, but I was quite excited to see the following in Greg's blog post announcing the news:

I am full-time on Ehcache. I have not had the time I would have liked to devote to Ehcache (I have been doing a miserly 10-15 hours per week for the past 6 years) but now I do. Look out!

Given what he's done so far with limited time, I'm looking forward to seeing what Greg can do when Ehcache becomes his full-time job!

For more information, see Terracotta's announcement, CTO of Terracotta Ari Zilka's blog post, or Alex Miller's blog post.

p.s. I submitted a patch that Greg ended up incorporating into Ehcache 1.6, so I feel a tiny bit of ownership toward the project – similar to the way I feel toward Tomcat.

Update: Terracotta and Ehcache are holding a webcast on August 20th at 4PM ET to further discuss the acquisition.  Also, I just submitted my second patch to Ehcache. :)

Tuesday, July 28, 2009

Attending SpringOne 2GX in October!

After much thought, I finally decided last night to register for the SpringOne 2GX conference running from October 19 through 22 in New Orleans.  The deadline for the super-early bird pricing is this Friday (July 31), so I thought I should make my decision.  I've been to talks on Groovy and Grails at NFJS and JavaOne, but I'm really looking forward to an entire conference devoted to those topics.  I hope to see you there!

Thursday, July 2, 2009

FogBugzReporter: NetBeans + Ivy = IvyBeans

(This is my second post in a series about FogBugzReporter, a small open source app that I originally wrote in Java and later ported to Groovy.  See the first post for more information and for links to other posts in the series as I write them.)

When I first ported FogBugzReporter to Groovy, I was able to take advantage of a free 1 year license for JetBrains IntelliJ IDEA (version 7) and its nice Groovy support.  I had good experiences with it, but when the year ran out, I was both reluctant to pay for a new license and curious to explore the Groovy and Grails support in NetBeans.  At the same time, I was interested in trying out Apache Ivy for dependency management.  As it turns out, Laurent Forêt wrote a plug-in for NetBeans called IvyBeans which integrates Ivy with the NetBeans internal build infrastructure.  So, if you reference a library in your ivy.xml, not only is it downloaded into your local repository (located in %USERPROFILE%/.netbeans/<netbeans_version>/modules/ext/cache on Windows) but it's also added as a NetBeans project dependency.  This post describes what it was like to move to NetBeans and start using Ivy.

Although I'd previously used NetBeans 6.1 and 6.5 for some small Grails apps, by the time I got around to moving FogBugzReporter into NetBeans, the 6.7 release process had already reached Milestone 2 or 3 (it has since been released!).  Since the Groovy/Grails plug-in for 6.7 provided better, more up-to-date support, I decided to jump directly to it.  After installing the base version and adding the Groovy/Grails plug-in, I looked over the options for opening the project in NetBeans.  I couldn't see any easy way to either import the project based on the existing IntelliJ files or create a new project pointing to the existing sources (any suggestions?), so I ended up doing something weird along the lines of creating a new project and checking out the files from Subversion on top of it.  I don't remember the exact steps, but even if I did I might not repeat them here, since I'm sure there's a better way to do it.  Once that was done, I was a bit disappointed to discover that I was unable to designate my Groovy script (MainFrame.groovy) as the project's main class.  This was even true after I converted the script into a class and gave it a main method.  Fortunately, it's still possible to run the app inside NetBeans by selecting that file and choosing Run File (Shift+F6) from the Run menu.

Next, it was time to try out Ivy and IvyBeans.  At the time, there was no up-to-date build available, so I built from HEAD, but at this point you can just download 1.1 Milestone 3.  Installation is as simple as extracting the zip you just downloaded and then following the basic plug-in install steps.  I searched on MVNRepository.com to find the appropriate org (a.k.a. group) and name for each of the two libraries my project uses.  I then removed the libraries from the NetBeans project, temporarily making the IDE unhappy.  After I added lines of the following form to ivy.xml and then executed a Clean and Build on the project, Ivy downloaded the libraries, IvyBeans made them available to the project, and the build completed successfully.  Pretty cool!

<dependency org="com.something" name="library_name" rev="1.2.3" conf="compile->*" />

My transition to NetBeans isn't totally finished, but it's almost there.  One thing I still need to figure out is what changes are needed to allow me to run an external build using the ant build.xml file generated by NetBeans – I think it involves specifying a few properties that are currently absent when ant is run standalone.

As I've said in most of my posts, please tell if you know of a better way to do any of what I've described above.  I'm definitely not an expert in NetBeans or Ivy.

Saturday, June 27, 2009

Embedded Groovy as an Application Extension Language

I recently worked with my client to add an extension mechanism (in this case, a very simple plug-in system) to their intranet Java web application.  It's initially meant for use by professional services staff and possibly other advanced users in the future.  Our first thought was to go with JavaScript via the Java Scripting API, since that pair of technologies was already in use elsewhere in the system for simple filtering expressions (e.g., "value > 10 && value < 100").  I wrote a few examples and discovered that the code quickly became a weird hybrid of Java and JavaScript that was very hard to read. ("Is that a Java String or a JavaScript String?…")  After a brief conversation with my client, we decided to instead go with Groovy for several reasons.  We can keep the code around as Strings for now, but easily compile it to class files later if our needs change.  Groovy's integration with Java is excellent and easy to understand.  If the user knows Java, but isn't comfortable with Groovy's many cool features, he or she can write normal Java (except for inner classes) and have it interpreted/compiled as Groovy.  What follows is a description of how I set it up.  Please let me know what you think of this approach, especially if you can suggest a way to improve it.

Each extension is a Groovy class extending a Java abstract adapter class that provides default implementations of all but one of the methods in a Java interface (ScriptingInterface).  The Java code used to load the extension gets a GroovyClassLoader using the following code:

GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());

I use the following code to get the relevant class and instantiate it via its no-arg constructor, catching the (entertainingly-named) MultipleCompilationErrorsException along with several other exceptions:

String code = "<Groovy>"; 
Class<? extends ScriptingInterface> clazz = loader.parseClass(code); 
ScriptingInterface script = clazz.newInstance();

Does that sound like a reasonable way to do it?  It definitely works, but I'm not sure it's the best way.

Update: Ack!  For some reason, my Blogger settings changed from "New Posts Have Comments" to "New Posts Do Not Have Comments" through no action of my own!  While I try to figure out how to fix it (now that this post is no longer new), you can add any comments to this post's listing on DZone.

Update2: Problem fixed.  It turned out to be possible to turn on comments for a single post via the Blogger post editor.