简体   繁体   English

从Artifactory插件使用MySQL数据库

[英]Using MySQL database from Artifactory plugin

I'm trying to write a monitoring plugin for Artifactory using MySQL. 我正在尝试使用MySQL为Artifactory编写一个监视插件。 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. 这个想法是,该插件将使用Artifactory公共API和一些命令行实用程序收集一些数据,然后将这些数据写入MySQL数据库,以便稍后进行分析。 The problem is that the plugin can't find the jdbc driver. 问题是该插件找不到jdbc驱动程序。 I placed the driver JAR in <artifactory-home>/etc/plugins/lib and I'm registering it like so: 我将驱动程序JAR放在<artifactory-home>/etc/plugins/lib并按如下方式进行注册:

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. 这导致com.mysql.jdbc.Driver上的ClassNotFoundException。 It seems the class loader used by Artifactory can't find the JAR. 看来Artifactory使用的类加载器找不到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. 可以将Artifactory配置为使用许多不同的数据库,包括MySQL,因此我认为必须有一种方法可以使用Artifactory使用的相同驱动程序,并且确实存在。

In the documentation for setting up Artifactory with MySQL it says: 使用MySQL设置Artifactory文档中说:

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. 下载MySQL JDBC驱动程序(可从MySQL网站获得),并将mysql-connector-java-.jar文件复制到服务器的共享lib目录中。 For example $TOMCAT_HOME/lib when installed as a service or $ARTIFACTORY_HOME/tomcat/lib in the standalone version. 例如,作为服务安装时的$ TOMCAT_HOME / lib或独立版本中的$ ARTIFACTORY_HOME / tomcat / lib。

Simply dropping the JDBC driver JAR in the shared lib directory makes it available for use within plugins. 只需将JDBC驱动程序JAR放到共享的lib目录中,即可在插件中使用它。 I imagine this approach would work for any other JARs too. 我想这种方法也适用于任何其他JAR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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