Skip to content

Grabbing A Library That Is Not In Maven

Some commercial vendors (I’m thinking of ones whose names start with ‘O’ in particular) haven’t quite got the concept of making their developer community’s lives easy and don’t publish their library files into any maven-accessible repository.

Putting aside for the moment the thought that perhaps such vendors might not deserve to have their software used, it may well happen that life (or your PHB) conspires against you and forces you to dance with the devil.

As a Groovy Grapes user (you are, aren’t you?), what are you to do?

You could start/populate your own Artifactory repository but that may be considered to be inappropriate for the userbase or might be too heavyweight for a quick-and-dirty script. What to do..what to do?

The answer lies in this stackoverflow question/answer session. I am recreating it here, for posterity…who knows, the link may go away one day…such is the way of the ‘net.

This is the sort of script fragment that I am considering:

@Grapes([
    @Grab('com.oracle:ojdbc6:11.2.0.3.0'),
    @GrabConfig(systemClassLoader=true, initContextClassLoader=true)
])
import groovy.sql.Sql

def oracleSql = Sql.newInstance("jdbc:oracle:thin:@192.168.1.64:1521:xe", "user", "password",
                      "oracle.jdbc.OracleDriver")
...

The trick is to manually create a grapes-compatible repository entry, mimicking what the grapes system would normally do.

Two things are required:

  • a compatible filesystem structure within your .groovy/grapes directory
  • an ivy config descriptor

The first looks like this:

The second looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
	<info organisation="com.oracle"
		module="ojdbc6"
		revision="11.2.0.3.0"
		status="release"
		publication="20140216144306"
		default="true"
	/>
	<configurations>
		<conf name="default" visibility="public"/>
	</configurations>
	<publications>
		<artifact name="ojdbc6" type="jar" ext="jar" conf="default"/>
	</publications>
</ivy-module>

Once this is all squared away Grape will Grab the specified jar quite happily.

Simple, when you know how.

Took me quite a while to track down though!

I extend my thanks to all those who contributed on stackoverflow.

Tags: ,

C, Java Enterprise Edition, JEE, J2EE, JBoss, Application Server, Glassfish, JavaServer Pages, JSP, Tag Libraries, Servlets, Enterprise Java Beans, EJB, Java Messaging Service JMS, BEA Weblogic, JBoss, Application Servers, Spring Framework, Groovy, Grails, Griffon, GPars, GAnt, Spock, Gradle, Seam, Open Source, Service Oriented Architectures, SOA, Java 2 Standard Edition, J2SE, Eclipse, Intellij, Oracle Service Bus, OSB