I'm getting a ClassNotFoundException with the message java.lang.ClassNotFoundException: com.mysql.jdbc.Driver when i run the generateTestDatabaseJooqSchema task from this jooq plugin. I don't know why this would be, since I included mysql:mysql-connector-java:6.0.5 in the buildscript dependencies on line 7.
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'
}
This is the full output I get, when I run the task:
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
I'm still not really comfortable with gradle so this might be a noob question, so i appreciate any help you can give.
This does not work as according to the documentation you need to put the appropriate database drive class to the special jooqRuntime configuration:
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' }
Related
Since I wanted to examine this source code, I imported it into Android Studio. I got a few other errors before and fixed them. This is annoying, now I have a new error.
I am getting this error:
Build file 'C:\Users\hange\Desktop\libgdx-demo-superjumper-master\desktop\build.gradle' line: 18
A problem occurred evaluating project ':desktop'.
> Could not get unknown property 'classesDir' for main classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput.
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
My "desktop\build.gradle" file looks like this. I specified line 18 there.
apply plugin: "java"
sourceCompatibility = 1.6
sourceSets.main.java.srcDirs = [ "src/" ]
project.ext.mainClassName = "com.badlogicgames.superjumper.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/assets");
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task dist(type: Jar) {
from files(sourceSets.main.output.classesDir) // THIS IS 18th LINE.
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);
manifest {
attributes 'Main-Class': project.mainClassName
}
}
dist.dependsOn classes
EDIT: My "build.gradle" file looks like this. But I noticed that it can't resolve the json library. Probably the error is here because we are pulling the gradle version from a json file on the internet.
import groovy.json.JsonSlurper // Cannot resolve symbol 'json'
buildscript {
ant.get(src: 'https://libgdx.com/service/versions.json', dest: 'versions.json')
def versionFile = file('versions.json')
def json
if (versionFile.exists()) {
json = new JsonSlurper().parseText(versionFile.text)
} else throw new GradleException("Unable to retrieve latest versions, please check your internet connection")
ext {
gdxVersion = json.libgdxRelease
roboVMVersion = json.robovmVersion
roboVMGradleVersion = json.robovmPluginVersion
androidToolsVersion = json.androidBuildtoolsVersion
androidSDKVersion = json.androidSDKVersion
androidGradleToolsVersion = json.androidGradleToolVersion
gwtVersion = json.gwtVersion
gwtGradleVersion = json.gwtPluginVersion
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath "org.wisepersist:gwt-gradle-plugin:$gwtGradleVersion"
classpath "com.android.tools.build:gradle:$androidGradleToolsVersion"
classpath "com.mobidevelop.robovm:robovm-gradle-plugin:$roboVMGradleVersion"
}
}
I'm posting the solution in case anyone else has the same problem:
androidToolsVersion, androidSDKVersion, androidGradleToolsVersion, gwtGradleVersion
These 4 variables are pulled from a json file on the internet, but the value pulled from the json file may not always work correctly. Make the variables compatible.
For example this code is using classesDir.The classesDir property was removed in Gradle 5.x.
If you pull to Gradle 4.8.1, you will get the error "Minimum supported Gradle version is 6.5. Current version is 4.8.1.". To fix this error you have to assign 3.2.x value compatible with 4.8.1 gradle version to the androidGradleToolsVersion variable.
androidGradleToolsVersion = "3.2.1"
I've gotten a Ratpack application working using gradle (v2.1.0) and jooq (v3.8.1) for generating class files.
Here's my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.ratpack:ratpack-gradle:1.5.4"
classpath "com.github.jengelman.gradle.plugins:shadow:1.2.3"
classpath "mysql:mysql-connector-java:5.1.34"
classpath 'org.jooq:jooq-codegen:3.8.1'
classpath 'com.h2database:h2:1.4.186'
}
}
plugins {
id "com.github.michaelruocco.embedded-mysql-plugin" version "2.1.7"
}
apply plugin: "io.ratpack.ratpack-java"
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "idea"
// db dump: mysqldump -P 3306 -h 127.0.0.1 -u embedded_user -ppassword --all-databases
def RDS_HOSTNAME = "localhost"
def RDS_PORT = 3306
def RDS_DB_NAME = "test"
def RDS_USERNAME = "embedded_user"
def RDS_PASSWORD = "password"
run {
environment "RDS_HOSTNAME", RDS_HOSTNAME
environment "RDS_PORT", RDS_PORT
environment "RDS_DB_NAME", RDS_DB_NAME
environment "RDS_USERNAME", RDS_USERNAME
environment "RDS_PASSWORD", RDS_PASSWORD
}
repositories {
jcenter()
}
ext {
ratpackPac4jVersion="2.0.0"
ratpackVersion="1.5.1"
pac4jVersion="2.1.0"
}
embeddedMysql {
url = 'jdbc:mysql://' + RDS_HOSTNAME + ':' + RDS_PORT + "/" + RDS_DB_NAME
username = RDS_USERNAME
password = RDS_PASSWORD
version = 'v5_7_latest'
}
import org.jooq.util.jaxb.*
import org.jooq.util.*
task jooqCodegen {
doLast {
String init = "$projectDir/src/main/resources/init.sql".replaceAll('\\\\', '/')
Configuration configuration = new Configuration()
.withJdbc(new Jdbc()
.withDriver("org.h2.Driver")
.withUrl("jdbc:h2:mem:todo;INIT=RUNSCRIPT FROM '$init'")
)
.withGenerator(new Generator()
.withDatabase(new Database()
.withName("org.jooq.util.h2.H2Database")
.withIncludes(".*")
.withExcludes("")
.withInputSchema("PUBLIC")
)
.withTarget(new Target()
.withDirectory("$projectDir/src/main/auto_generated")
.withPackageName("jooq")))
GenerationTool.generate(configuration)
}
}
run.dependsOn startEmbeddedMysql
dependencies {
runtime "org.slf4j:slf4j-simple:1.7.25"
compile "org.pac4j:ratpack-pac4j:${ratpackPac4jVersion}"
compile "io.ratpack:ratpack-groovy:${ratpackVersion}"
compile "io.ratpack:ratpack-test:${ratpackVersion}"
compile "org.pac4j:pac4j-core:${pac4jVersion}"
compile "org.pac4j:pac4j-oauth:${pac4jVersion}"
compile "org.pac4j:pac4j-openid:${pac4jVersion}"
compile "org.pac4j:pac4j-http:${pac4jVersion}"
compile "org.pac4j:pac4j-gae:${pac4jVersion}"
compile "org.pac4j:pac4j-oidc:${pac4jVersion}"
compile "org.pac4j:pac4j-jwt:${pac4jVersion}"
compile ratpack.dependency('hikari')
compile "ch.qos.logback:logback-classic:1.0.13"
compile group: 'io.ratpack', name: 'ratpack-thymeleaf', version: '1.4.0-rc-3'
compile "mysql:mysql-connector-java:5.1.34"
compile 'org.jooq:jooq:3.8.1'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.2.Final'
}
mainClassName = "xyz.mealsahead.Main"
I started working with the jooq API and realized I'm using an old version of jooq, so want to switch to the newer API.
The first thing I tried was just changing the two jooq references from 3.8.1 to 3.11.2. This caused problems as it seems the jooq version changed the API such that the jooq config no longer works:
> startup failed:
build file build.gradle': 72: unable to resolve class Target
# line 72, column 19.
.withTarget(new Target()
^
build file build.gradle': 66: unable to resolve class Database
# line 66, column 23.
.withDatabase(new Database()
^
build file build.gradle': 65: unable to resolve class Generator
# line 65, column 22.
.withGenerator(new Generator()
^
etc.
jooq has an example for a gradle setup, but I don't understand how it could work: https://www.jooq.org/doc/3.11/manual/code-generation/codegen-gradle/. The strange thing is buildscript block in that example isn't at the top, which from what I see in my terminal and online is not allowed:
build.gradle': 24: only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
so I don't know how that example would work unless it's for a different version of gradle than I have (earlier or later).
Looking at the doc for the jooq-gradle plugin (https://github.com/etiennestuder/gradle-jooq-plugin), it has pretty clear steps for setting up the gradle script, so I modified the build.gradle file to look like the following:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.ratpack:ratpack-gradle:1.5.4"
classpath "com.github.jengelman.gradle.plugins:shadow:1.2.3"
classpath "mysql:mysql-connector-java:5.1.34"
classpath 'com.h2database:h2:1.4.186'
classpath 'nu.studer:gradle-jooq-plugin:3.0.1'
}
}
plugins {
id "com.github.michaelruocco.embedded-mysql-plugin" version "2.1.7"
}
apply plugin: 'nu.studer.jooq'
apply plugin: "io.ratpack.ratpack-java"
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "idea"
// db dump: mysqldump -P 3306 -h 127.0.0.1 -u embedded_user -ppassword --all-databases
def RDS_HOSTNAME = "localhost"
def RDS_PORT = 3306
def RDS_DB_NAME = "test"
def RDS_USERNAME = "embedded_user"
def RDS_PASSWORD = "password"
run {
environment "RDS_HOSTNAME", RDS_HOSTNAME
environment "RDS_PORT", RDS_PORT
environment "RDS_DB_NAME", RDS_DB_NAME
environment "RDS_USERNAME", RDS_USERNAME
environment "RDS_PASSWORD", RDS_PASSWORD
}
repositories {
jcenter()
}
ext {
ratpackPac4jVersion="2.0.0"
ratpackVersion="1.5.1"
pac4jVersion="2.1.0"
}
embeddedMysql {
url = 'jdbc:mysql://' + RDS_HOSTNAME + ':' + RDS_PORT + "/" + RDS_DB_NAME
username = RDS_USERNAME
password = RDS_PASSWORD
version = 'v5_7_latest'
}
dependencies {
jooqRuntime 'com.h2database:h2:1.4.193'
}
jooq {
String init = "$projectDir/src/main/resources/init.sql".replaceAll('\\\\', '/')
version = '3.11.2'
edition = 'OSS'
sample(sourceSets.main) {
jdbc {
driver = "org.h2.Driver" //'org.postgresql.Driver'
url = "jdbc:h2:mem:todo;INIT=RUNSCRIPT FROM '$init'" //'jdbc:postgresql://localhost:5432/sample'
user = 'sa'
password = ''
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
database {
name = 'org.jooq.meta.h2.H2Database'
includes = '.*'
excludes = ''
inputSchema = 'public'
}
generate {
relations = true
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
}
target {
directory = "$projectDir/src/main/auto_generated"
packageName = 'jooq'
}
}
}
}
run.dependsOn startEmbeddedMysql
dependencies {
runtime "org.slf4j:slf4j-simple:1.7.25"
compile "org.pac4j:ratpack-pac4j:${ratpackPac4jVersion}"
compile "io.ratpack:ratpack-groovy:${ratpackVersion}"
compile "io.ratpack:ratpack-test:${ratpackVersion}"
compile "org.pac4j:pac4j-core:${pac4jVersion}"
compile "org.pac4j:pac4j-oauth:${pac4jVersion}"
compile "org.pac4j:pac4j-openid:${pac4jVersion}"
compile "org.pac4j:pac4j-http:${pac4jVersion}"
compile "org.pac4j:pac4j-gae:${pac4jVersion}"
compile "org.pac4j:pac4j-oidc:${pac4jVersion}"
compile "org.pac4j:pac4j-jwt:${pac4jVersion}"
compile ratpack.dependency('hikari')
compile "ch.qos.logback:logback-classic:1.0.13"
compile group: 'io.ratpack', name: 'ratpack-thymeleaf', version: '1.4.0-rc-3'
compile "mysql:mysql-connector-java:5.1.34"
compile 'org.jooq:jooq'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.2.Final'
}
mainClassName = "xyz.mealsahead.Main"
Running "gradle run" works fine, so I assume it's downloading that new version of jooq, but now I don't see any code generated. I see the following message:
$ gradle generateSampleJooqSchemaSource
:generateSampleJooqSchemaSource UP-TO-DATE
Can someone tell me if I:
am using the appropriate gradle-jooq plugin for this?
have misconfigured the new generator syntax from the previous version?
Regarding your manual setup of the jOOQ code generator
Indeed, due to the upcoming modularisation of jOOQ 3.12, some split packages had to be renamed, namely the org.jooq.util package. In your manual setup, you need to change your imports from:
import org.jooq.util.jaxb.*
import org.jooq.util.*
To
import org.jooq.codegen.*
import org.jooq.meta.jaxb.*
import org.jooq.meta.*
Regarding your usage of the third party Gradle plugin
Do note that schema names are case sensitive, so probably it would help replacing this:
inputSchema = 'public'
By this
inputSchema = 'PUBLIC'
You already had it correct earlier: .withInputSchema("PUBLIC")
I started Kotlin/JS react library on kotlin frontend Gradle plugin. I have the following error:
> Task :web:webpack-bundle FAILED
js/kotlinx-html-js.js
Module not found: Error: Can't resolve 'kotlin' in '/home/marcin/Projects/EduKotlinAcademy/web/build/node_modules_imported/kotlinx-html-js'
# ../node_modules_imported/kotlinx-html-js/kotlinx-html-js.js 3:4-42
# ../node_modules_imported/kotlin-react-dom/kotlin-react-dom.js
# ./web.js
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':web:webpack-bundle'.
> node webpack.js failed (exit code = 2)
It looks like dependency to Kotlin can't be found on kotlinx-html-js. Although I define Kotlin and it should be generated fine.
For this configuration:
group "org.kotlinacademy" version "1.0-SNAPSHOT"
apply plugin: 'kotlin2js'
apply plugin: 'org.jetbrains.kotlin.frontend'
repositories {
jcenter()
}
kotlinFrontend {
npm {
dependency("webpack-cli", "v2.0.12")
dependency("react", "15.6.1")
dependency("react-dom", "15.6.1")
dependency("react-router-dom", "4.2.2")
dependency("jquery")
dependency("react-markdown")
}
sourceMaps = true
webpackBundle {
bundleName = "main"
contentPath = file('src/main/web')
proxyUrl = "http://localhost:8090"
}
}
dependencies {
compile project(':common-js')
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:0.22.5"
compile("org.jetbrains.kotlinx:kotlinx-html-js:0.6.10") { force = true }
compile 'org.jetbrains:kotlin-react:16.3.1-pre.27-kotlin-1.2.30'
compile "org.jetbrains:kotlin-react-dom:16.3.1-pre.27-kotlin-1.2.30"
}
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
kotlinOptions.main = "call" }
To fix it, add:
dependency("kotlin", kotlin_version)
To NPM dependencies
I am trying to deploy a war file on a remote JBoss 5.1.0.GA container, using a gradle build file and the Gradle Cargo plugin by Benjamin Muschko (https://github.com/bmuschko/gradle-cargo-plugin).
I am experiencing a java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory when launching the cargoDeployRemote task on a very simple project.
The post about Cargo deployment on a JBoss 5.1.0.GA using Maven plugin helped me setting up the dependencies.
The missing class NamingContextFactory is also defined inside the jboss-as-varia dependency for example. Obviously, I must be missing something.
The project is only a folder with the following Gradle script, nothing more.
I must add that I run the build script from inside a linux virtual machine, a virtualbox guest running ArchLinux, and I want to remotely deploy on a JBoss 5.1.0.GA server running on the host. I am able to access the JBoss via the gateway address (10.0.2.2) from the guest, so I guess this is not the issue here.
I tried to provide the most simple gradle build file for showing this problem.
Any clue on what should be done to make this work ? Any help appreciated.
Here's my build.gradle file:
apply plugin: 'war'
apply plugin: 'com.bmuschko.cargo'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.1.1'
}
}
repositories {
mavenCentral()
dependencies {
providedCompile 'org.jboss.jbossas:jboss-as-jbossas-remoting:5.1.0.GA'
providedCompile 'org.jboss.jbossas:jboss-as-client:5.1.0.GA'
providedCompile 'org.jboss.jbossas:jboss-as-varia:5.1.0.GA'
providedCompile 'org.jboss.integration:jboss-profileservice-spi:5.1.0.GA'
}
}
cargo {
containerId = 'jboss51x'
port = 8080
remote {
username = "admin"
password = "admin"
hostname = "10.0.2.2"
}
deployable {
context = 'myawesomewebapp'
}
}
Here's is the output for 'gradle cargoDeployRemote -i' showing the error:
Executing task ':cargoDeployRemote' (up-to-date check took 0.002 secs)
due to: Task.upToDateWhen is false. Container ID = jboss51x
Deployable artifacts = [/home/gerald/testapp/build/libs/testapp.war]
Starting action 'deploy' for remote container 'JBoss 5.1.x' on
'http://10.0.2.2:8080' Container properties = [:] :cargoDeployRemote
FAILED :cargoDeployRemote (Thread[Daemon worker Thread 14,5,main])
completed. Took 0.588 secs.
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':cargoDeployRemote'. org.codehaus.cargo.container.ContainerException: Failed to create
deployer with implementation class
org.codehaus.cargo.container.jboss.JBoss51xRemoteDeployer for the
parameters (container [id = [jboss51x]], deployer type [remote]).
And here is the exception:
Caused by: org.codehaus.cargo.container.ContainerException: Failed to create deployer with implementation class org.codehaus.cargo.container.jboss.JBoss51xRemoteDeployer for the parameters (container [id = [jboss51x]], deployer type [remote]).
at org.codehaus.cargo.generic.spi.AbstractGenericHintFactory.createImplementation(AbstractGenericHintFactory.java:156)
at org.codehaus.cargo.generic.spi.AbstractIntrospectionGenericHintFactory.createImplementation(AbstractIntrospectionGenericHintFactory.java:93)
at org.codehaus.cargo.generic.deployer.DefaultDeployerFactory.createDeployer(DefaultDeployerFactory.java:140)
at org.codehaus.cargo.generic.deployer.DefaultDeployerFactory.createDeployer(DefaultDeployerFactory.java:160)
at org.codehaus.cargo.ant.CargoTask.executeActions(CargoTask.java:758)
at org.codehaus.cargo.ant.CargoTask.execute(CargoTask.java:577)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
... 70 more
Caused by: java.lang.reflect.InvocationTargetException
at org.codehaus.cargo.generic.deployer.DefaultDeployerFactory.createInstance(DefaultDeployerFactory.java:244)
at org.codehaus.cargo.generic.deployer.DefaultDeployerFactory.createInstance(DefaultDeployerFactory.java:42)
at org.codehaus.cargo.generic.spi.AbstractGenericHintFactory.createImplementation(AbstractGenericHintFactory.java:150)
... 77 more
Caused by: org.codehaus.cargo.util.CargoException: Cannot locate the JBoss connector classes! Make sure the required JBoss JARs (or Maven dependencies) are in CARGO's classpath.
More information on: http://cargo.codehaus.org/JBoss+Remote+Deployer
at org.codehaus.cargo.container.jboss.JBoss5xRemoteDeployer.<init>(JBoss5xRemoteDeployer.java:161)
at org.codehaus.cargo.container.jboss.JBoss51xRemoteDeployer.<init>(JBoss51xRemoteDeployer.java:41)
... 80 more
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1366)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1315)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
at org.codehaus.cargo.container.jboss.JBoss5xRemoteDeployer.<init>(JBoss5xRemoteDeployer.java:156)
... 81 more
I found the answer following resources:
https://discuss.gradle.org/t/dependency-classpath-issue-when-deploying-a-war-via-cargo-and-com-bmuschko-cargo-on-remote-jboss-5-1-0-ga/9943
https://github.com/bmuschko/gradle-cargo-plugin/issues/78
The summary of what I had to do to fix the problem is that I had to have cargo dependencies as cargo configuration in first level dependencies closure (not buildscript.dependencies closure).
apply plugin: 'ear'
apply plugin: 'com.bmuschko.cargo'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.2.1'
}
}
repositories {
//Order of repositories is significant and will effect finding of jaas module
maven {
name = "JBoss Deprecated Maven Repository"
url = "https://repository.jboss.org/nexus/content/repositories/deprecated"
}
maven {
url 'https://repository.jboss.org/nexus/content/groups/public/'
}
maven {
name = "JBoss.org third party releases repository"
url = "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases"
}
mavenCentral()
jcenter()
}
dependencies {
// My app specific modules taken out from here
def cargoVersion = '1.4.5'
cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
"org.codehaus.cargo:cargo-ant:$cargoVersion"
cargo 'org.jboss.jbossas:jboss-as-jbossas-remoting:5.1.0.GA'
cargo 'org.jboss.jbossas:jboss-as-client:5.1.0.GA'
cargo 'org.jboss.jbossas:jboss-as-varia:5.1.0.GA'
cargo 'org.jboss.integration:jboss-profileservice-spi:5.1.0.GA'
}
cargo {
containerId = 'jboss51x'
port = 8009
remote {
hostname = project.hostname
username = project.username
password = project.password
}
}
I have got the following gradle script. It results in No suitable driver found error which I found strange.
buildscript {
repositories{
maven {
url = 'http://localhost:8090/nexus/content/groups/public/'
}
}
dependencies {
classpath 'com.oracle:ojdbc6:11.2.0.4.0'
}
}
task sql << {
def url = 'jdbc:oracle:thin:#' + project.properties['db_hostname'] + ':' + project.properties['db_port'] + ':' + project.properties['db_sid']
println 'sql, db url:' + url
def driverName = 'oracle.jdbc.OracleDriver'
Class.forName(driverName).newInstance();
groovy.sql.Sql sql = groovy.sql.Sql.newInstance(
url,
project.properties['db_username'],
project.properties['db_password'],
driverName
)
}
The error is:
Tasks to be executed: [task ':sql']
:sql (Thread[main,5,main]) started.
:sql
Executing task ':sql' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
truncating, db url:jdbc:oracle:thin:#LOCALHOST:1521:orcl
:sql FAILED
:sql (Thread[main,5,main]) completed. Took 0.105 secs.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/fran/projects/jua/build.gradle' line: 49
* What went wrong:
Execution failed for task ':sql'.
> No suitable driver found for jdbc:oracle:thin:#LOCALHOST:1521:orcl
* Try:
Run with --debug option to get more log output.
The driver jar is being loaded in a different classloader context than the Sql class. To fix it, try adding this:
// Add jars resolved by buildscript classpath configuration to the classloader which Sql will use
URLClassLoader loader = groovy.sql.Sql.class.classLoader
project.buildscript.configurations.classpath.each { File file ->
loader.addURL(file.toURL())
}
prior to the call to Sql.newInstance(). It will make all your classpath dependencies available to the Groovy classloader which loads the Sql class. The Class.forName() should not be neccesary.
See the discussion here for more information:
http://gradle.1045684.n5.nabble.com/using-jdbc-driver-in-a-task-fails-td1435189.html
For me that didn't work (Gradle 2.12).
But instead of performing:
Class.forName("org.h2.Driver")
I did:
groovy.sql.loadDriver("org.h2.Driver")
The Groovy Sql.loadDriver method does some nifty classloader stuff.
You should use something like this:
configurations {
db2database
}
buildscript {
dependencies {
classpath('com.ibm.db2:db2jcc4:10.5.5')//db2 driver for gradle task
}
}
dependencies {
db2database "com.ibm.db2:db2jcc4:10.5.5" //db2 driver for configuration
}
//load drivers for gradle tasks
configurations.db2database.each {
GroovyObject.class.classLoader.addURL(it.toURI().toURL())
}
....
Sql sql = Sql.newInstance(
envProps.getProperty('dbUri'),
envProps.getProperty('dbUsername'),
envProps.getProperty('dbPassword'),
envProps.getProperty('dbDriverClassName')
)
println sql.rows("SELECT * FROM TEST.TEST")