STOP THE PRESS!!!
The following post is now THANKFULLY obsolete. Microsoft have done the decent thing and provided their JDBC driver via maven.
One day they may even make that driver comply with the entirety of the JDBC spec!
The advice below relates to the use of driver versions not presently on maven central. Perhaps required if you’re fixed to an old version of the server or driver.
Similarly, the advice below only makes sense if you have ZERO access to an artefact repository that you could just upload your driver into.
It’s a bit of a nuisance that Microsoft and Oracle do not publish their jar files for database connections in Maven central. Guys sort it out – it should not be that much of an issue.
I wanted to create a web application which connected to SQL server. The truth is that although there’s an open source alternative to the Microsoft SQL driver – jtds – it proved not to be as reliable as we wanted. So we needed the genuine article. We’re licensed to use it, so there’s no problem. Except it’s not in Maven and our project used a Maven build.
Here’s the right answer:
Install the Microsoft JDBC driver into your artifactory/Nexus with a suitable set of attributes and then your Maven build will pick it up from there
That wasn’t what I wanted. I wanted to have all the files for this build either within my source code repository or within the cloud. A middle-man repository for this project, risked the possibility that if the repository changed, and the project, which is not built more than once in a blue moon, wasn’t kept up to date, it would never build again. A more self-contained project was my desire and is more in keeping with best practice.
Advice number 2:
Have the jar in a source code repo somewhere and have a script that can install it in the nearest Maven repository
Not bad advice. Not what I wanted to do.
In the end, I used two tricks.
- Put the jar file in a local lib folder and provide the dependency from there (in fact the dependency wasn’t needed at all at compile time as JDBC generally works on class names at run time).
- Ensure that the contents of the lib folder were packaged into the war file by the war plug in.
Here’s how it looks:
Maven dependency – in case you need compile time access to the jar.
This genuinely works. It’s a decent workaround, but it’s a shame that Maven and Microsoft don’t work a bit more flexibly.