我正在尝试使用 MySQL 为 Artifactory 编写一个监控插件。这个想法是,该插件将使用 Artifactory 公共(public) API 和一些命令行实用程序收集一些数据,然后将该数据写入 MySQL 数据库以供稍后分析。问题是插件找不到jdbc驱动。我将驱动程序 JAR 放在 <artifactory-home>/etc/plugins/lib
中我像这样注册它:
def sql = Sql.newInstance('jdbc:mysql://localhost:3306/artifactoryTest', <user>, <pass>, 'com.mysql.jdbc.Driver')
这会导致 com.mysql.jdbc.Driver 上出现 ClassNotFoundException。 Artifactory 使用的类加载器似乎找不到 JAR。
有没有办法让这个工作成功,还是我找错了树?我知道可能有一些数据库技术更适合此目的,但对于这样的基本用例来说,许多技术似乎有些过分,我希望使其尽可能简单。
最佳答案
事实证明这确实是可能的。 Artifactory 可以配置为使用许多不同的数据库,包括 MySQL,所以我想一定有一种方法可以使用 Artifactory 使用的相同驱动程序,而且确实存在。
在 documentation for setting up Artifactory with MySQL它说:
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.
只需将 JDBC 驱动程序 JAR 放入共享 lib 目录中即可在插件中使用。我想这种方法也适用于任何其他 JAR。
关于mysql - 使用 Artifactory 插件中的 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48907749/