简体   繁体   中英

Using MySQL database from Artifactory plugin

I'm trying to write a monitoring plugin for Artifactory using MySQL. The idea is that the plugin will collect some data using the Artifactory public API and some command line utilities, then write that data to a MySQL database to be analysed later. The problem is that the plugin can't find the jdbc driver. I placed the driver JAR in <artifactory-home>/etc/plugins/lib and I'm registering it like so:

def sql = Sql.newInstance('jdbc:mysql://localhost:3306/artifactoryTest', <user>, <pass>, 'com.mysql.jdbc.Driver')

This results in a ClassNotFoundException on com.mysql.jdbc.Driver. It seems the class loader used by Artifactory can't find the JAR.

Is there a way to make this work or am I barking up the wrong tree? I'm aware there may be some database technologies that would be better suited for this purpose but many seem like overkill for such a basic use case and I'd like to keep it as simple as possible.

Turns out this is indeed possible. Artifactory can be configured to use a number of different databases, including MySQL, so I figured there must be a way to use the same driver that Artifactory uses and indeed there is.

In the documentation for setting up Artifactory with MySQL it says:

Download the MySQL JDBC driver (available from the MySQL website) and copy the mysql-connector-java-.jar file into the server's shared lib directory. For example $TOMCAT_HOME/lib when installed as a service or $ARTIFACTORY_HOME/tomcat/lib in the standalone version.

Simply dropping the JDBC driver JAR in the shared lib directory makes it available for use within plugins. I imagine this approach would work for any other JARs too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM