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 is not really a maven dependency - it's been hacked into the WAR file via the WAR plug-in lower down
if you want it as part of a local deployment to a tomcat within your development environment, then add the jar
to your tomcat server directly as the Eclipse locally-produced deployment will not have this in it -->
<!-- Adds the jars from the lib folder into the war package
this does not work for local dev-deployments to a local tomcat
from Eclipse - you'll have to deploy these jars to your tomcat
directly. It _should_ work for deploying a war file to any tomcat -->
This genuinely works. It’s a decent workaround, but it’s a shame that Maven and Microsoft don’t work a bit more flexibly.