使用 mysql-连接器时构建脚本中的 ClassNotFoundException
ClassNotFoundException in buildscript when using the mysql-connector
当我 运行 来自此 jooq plugin 的 generateTestDatabaseJooqSchema
任务时,我收到 ClassNotFoundException
消息 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
。我不知道为什么会这样,因为我在第 7 行的构建脚本依赖项中包含了 mysql:mysql-connector-java:6.0.5
。
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'mysql:mysql-connector-java:6.0.5'
classpath 'nu.studer:gradle-jooq-plugin:2.0.0'
}
}
plugins {
id 'nu.studer.jooq' version '2.0.0'
id 'org.flywaydb.flyway' version '4.0.3'
}
apply plugin: 'java'
apply plugin: 'idea'
// database connection information
def database_name = 'cloudpass-api'
def database_url = 'jdbc:mysql://localhost:3306/cloudpass-api'
def database_user = 'root'
def database_pass = 'password'
jooq {
testDatabase(sourceSets.main) {
jdbc {
driver = 'com.mysql.jdbc.Driver'
url = database_url
user = database_user
password = database_pass
schema = database_name
}
generator {
name = 'org.jooq.util.JavaGenerator'
database {
name = 'org.jooq.util.mysql.MySQLDatabase'
inputSchema = database_name
}
generate {
relations = true
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
}
target {
packageName = 'cloudpass.database'
}
}
}
}
flyway {
url = database_url
user = database_user
password = database_pass
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'mysql:mysql-connector-java:6.0.5'
compile 'org.jooq:jooq'
compile 'com.maxmind.geoip2:geoip2:2.8.0'
testCompile 'junit:junit:4.12'
}
这是我得到的完整输出,当我 运行 任务时:
C:\Users\Thomas\Projects\cloudpass-api-java>gradle generateTestDatabaseJooqSchemaSource
Starting a Gradle Daemon (subsequent builds will be faster)
:generateTestDatabaseJooqSchemaSource
nov. 06, 2016 7:54:15 AM org.jooq.tools.JooqLogger info
INFO: Initialising properties : C:\Users\Thomas\Projects\cloudpass-api-java\build\tmp\jooq\config.xml
nov. 06, 2016 7:54:16 AM org.jooq.tools.JooqLogger error
SEVERE: Cannot read C:\Users\Thomas\Projects\cloudpass-api-java\build\tmp\jooq\config.xml. Error : com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jooq.util.GenerationTool.loadClass(GenerationTool.java:591)
at org.jooq.util.GenerationTool.run(GenerationTool.java:248)
at org.jooq.util.GenerationTool.generate(GenerationTool.java:198)
at org.jooq.util.GenerationTool.main(GenerationTool.java:170)
:generateTestDatabaseJooqSchemaSource FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateTestDatabaseJooqSchemaSource'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_101\bin\java.exe'' finished with non-zero exit value -1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.831 secs
我对 gradle 仍然不是很满意,所以这可能是一个菜鸟问题,所以我很感激你能提供的任何帮助。
这不起作用,因为根据文档您需要将适当的数据库驱动器 class 放入特殊的 jooqRuntime
配置:
Depending on which database you are connecting to, you need to put the
corresponding driver on the generator's classpath.
dependencies { jooqRuntime 'postgresql:postgresql:9.1-901.jdbc4' }
当我 运行 来自此 jooq plugin 的 generateTestDatabaseJooqSchema
任务时,我收到 ClassNotFoundException
消息 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
。我不知道为什么会这样,因为我在第 7 行的构建脚本依赖项中包含了 mysql:mysql-connector-java:6.0.5
。
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'mysql:mysql-connector-java:6.0.5'
classpath 'nu.studer:gradle-jooq-plugin:2.0.0'
}
}
plugins {
id 'nu.studer.jooq' version '2.0.0'
id 'org.flywaydb.flyway' version '4.0.3'
}
apply plugin: 'java'
apply plugin: 'idea'
// database connection information
def database_name = 'cloudpass-api'
def database_url = 'jdbc:mysql://localhost:3306/cloudpass-api'
def database_user = 'root'
def database_pass = 'password'
jooq {
testDatabase(sourceSets.main) {
jdbc {
driver = 'com.mysql.jdbc.Driver'
url = database_url
user = database_user
password = database_pass
schema = database_name
}
generator {
name = 'org.jooq.util.JavaGenerator'
database {
name = 'org.jooq.util.mysql.MySQLDatabase'
inputSchema = database_name
}
generate {
relations = true
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
}
target {
packageName = 'cloudpass.database'
}
}
}
}
flyway {
url = database_url
user = database_user
password = database_pass
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'mysql:mysql-connector-java:6.0.5'
compile 'org.jooq:jooq'
compile 'com.maxmind.geoip2:geoip2:2.8.0'
testCompile 'junit:junit:4.12'
}
这是我得到的完整输出,当我 运行 任务时:
C:\Users\Thomas\Projects\cloudpass-api-java>gradle generateTestDatabaseJooqSchemaSource
Starting a Gradle Daemon (subsequent builds will be faster)
:generateTestDatabaseJooqSchemaSource
nov. 06, 2016 7:54:15 AM org.jooq.tools.JooqLogger info
INFO: Initialising properties : C:\Users\Thomas\Projects\cloudpass-api-java\build\tmp\jooq\config.xml
nov. 06, 2016 7:54:16 AM org.jooq.tools.JooqLogger error
SEVERE: Cannot read C:\Users\Thomas\Projects\cloudpass-api-java\build\tmp\jooq\config.xml. Error : com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jooq.util.GenerationTool.loadClass(GenerationTool.java:591)
at org.jooq.util.GenerationTool.run(GenerationTool.java:248)
at org.jooq.util.GenerationTool.generate(GenerationTool.java:198)
at org.jooq.util.GenerationTool.main(GenerationTool.java:170)
:generateTestDatabaseJooqSchemaSource FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateTestDatabaseJooqSchemaSource'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_101\bin\java.exe'' finished with non-zero exit value -1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.831 secs
我对 gradle 仍然不是很满意,所以这可能是一个菜鸟问题,所以我很感激你能提供的任何帮助。
这不起作用,因为根据文档您需要将适当的数据库驱动器 class 放入特殊的 jooqRuntime
配置:
Depending on which database you are connecting to, you need to put the corresponding driver on the generator's classpath.
dependencies { jooqRuntime 'postgresql:postgresql:9.1-901.jdbc4' }