Friday, March 18, 2016

Teaching an Old Dog new Tricks -- Part 1

One of the challenges of being a solo developer is that you get a favorite set of tools and you stick with it for so long that you often don't keep your skills up to date. But, you can teach an old fart new tricks.

Unfortunately, sometimes when I have to learn those new tricks is when someone has added that tool to my bag without me looking at it first.  I encountered that with Maven today.  I've been using OpenShift to deploy my Pubmed for HealthIT Standards project, and it uses Maven to build my Java sources when I push to my git repository.

But I'm of the old school where you found your libraries, downloaded them, dropped them into WEB-INF/lib and went to town.  That doesn't work anymore, and so I had to learn to use Maven.
Unfortunately, the maven documentation isn't designed for old farts like me and so it took me a little bit to figure out what should probably be obvious.  If you are a young blood, this post probably will seem a bit stupid, but I'm betting there are enough others like me out there that it will be just the thing.

Where before you: Found your libraries, downloaded them onto your computer, moved them into a build structure, and then copied them into WEB-INF\lib when you deploy or build, you skip all that when using a maven build.

Instead, go find how your library is identified in Maven's repository.  Most systems that use maven will tell you with some XML that looks like this.

<dependency>
 <groupId>org.apache.pdfbox</groupId>
 <artifactId>pdfbox</artifactId>
 <version>1.8.11</version>
</dependency>

What you do is add that XML to your pom.xml file for your build, and it will automatically download the jar file from the Maven central repository.  If, for some reason you need to get a library from some other repository, you need to add a line like this your pom.xml file:

<repository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>

There, now you are done, and off you go.  I love the simplicity of it, I just wish someone would have explained it for a guy like me who's been used to doing things the hard way for three or more decades.

--  Keith

P.S.  I have a number of these to write, because I've been learning a few new tricks lately.  Three upcoming posts are on MongoDB and Bootstrap (which I'm using now), and AngularJS, which I hope to be using soon.  The first two were mostly straightforward, but I'm finding the last to be a bit, well, hopelessly confusing.  I really don't care about dependency injection (actually I do, but not in chapter 1).  What I want to learn is how to quickly build something, and so far, the three books I've look at through my Safari subscription have been nearly useless.

P.P.S. The reason I had to learn Maven is because my build broke when I added a Jar to WEB-INF/lib, but which was needed for the Maven compilation.  For some reason, Eclipse set the class path right for the java build (probably because I made a manual adjustment to it), but Maven wasn't configured correctly.  Fortunately, it only took me an hour or so to figure it all out and get my build going again.

0 comments:

Post a Comment