I'm adding a downloaded jar to my lib folder, but when I try to use it doesn't work.
Here is the code:
// make sure the ClassLoader has the MonetDB JDBC driver loaded
Class cls = Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");
// request a Connection to a MonetDB server running on 'localhost'
Connection con = DriverManager.getConnection("jdbc:monetdb://localhost/testDB", "monetdb", "monetdb");
Statement st = con.createStatement();
There is no code problems because I created a java app with same code and it works, the problem is grails is not taking the jar into the class path.
So finaly here is my buildConfig.groovy
grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
grailsCentral()
mavenLocal()
mavenCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.27'
}
plugins {
build ":tomcat:8.0.22"
build(":release:3.0.1",
":rest-client-builder:1.0.3") {
export = false
}
}
Take a look at this document:
http://grails.github.io/grails-doc/latest/guide/conf.html#dataSource
Define the monetdb as a dependency using BuildConfig.groovy
by adding this 'monetdb:monetdb-jdbc:2.8'
Then update the entries in the Datasource.groovy file.
Now from your controller yuo have to inject the datasource.
SampleController{
def dataSource
def index(){
def sql = new Sql(dataSource)
sql.executeUpdate('select * from testdb.something')
}
}
Related
I started a brand new grails 2.2 app. I want to add qrcode plugin.
https://plugins.grails.org/plugin/technipelago/qrcode
the documentation says for grails 2 app use
grails.project.dependency.resolution = {
// ...
plugins {
compile ':qrcode:0.7'
// ...
}
}
here is my buildconfig after adding qrcode plugin
grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
// uncomment (and adjust settings) to fork the JVM to isolate classpaths
//grails.project.fork = [
// run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256]
//]
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.20'
}
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.1.6"
build ":tomcat:$grailsVersion"
runtime ":database-migration:1.2.1"
compile ':cache:1.0.1'
compile ':qrcode:0.7'
}
}
when i build
it says
|Loading Grails 2.2.0
|Configuring classpath
Error |
Failed to resolve dependencies (Set log level to 'warn' in BuildConfig.groovy for more information):
- org.grails.plugins:qrcode:0.7
I appreciate any help as to integrating qrcode plugin. I dont need latest version. I just need to make qrcode plugin to work. Old version will do.
Thanks for the help!
First add local maven repo (mavenLocal()) to your in BuildConfig.groovy:
repositories {
inherits true
grailsPlugins()
mavenLocal()
mavenCentral()
}
Then add dependency in BuildConfig.groovy:
dependencies {
compile "org.grails.plugins:qrcode:0.7"
}
If by adding in dependency not work then add it to plugins:
plugins {
compile(':qrcode:0.7')
}
You can refer repo of this plugin where you can see available versions.
Hope this helps you.
Try version 0.7.1
I looks
It is also for Grails 2.x and should load just fine by putting it in the plugins {} section like you did.
trying to get the code for a legacy system compiling (grails 1.3.9) and I've hit a barrier when it tried to install the mail-1.0.1 plugin. Seems that this succeeds but then then proceeds to try to install the mail-1.4.3.jar as a plugin and fails roling back mail 1.0.1. I've done the google thing and there is only a single reference (bug report) which has been of no help
Could the repositories be causing it?
Here is the specific build error
------------------------------------------
grails create-constraint
[delete] Deleting directory /home/blake/.grails/1.3.9/projects/egrants-grails-1.3.9/resources
Installing zip /home/blake/.ivy2/cache/org.grails.plugins/mail/zips/mail-1.0.1.zip... ...
[mkdir] Created dir: /home/blake/.grails/1.3.9/projects/egrants-grails-1.3.9/plugins/mail-1.0.1
[unzip] Expanding: /home/blake/.ivy2/cache/org.grails.plugins/mail/zips/mail-1.0.1.zip into /home/blake/.grails/1.3.9/projects/egrants-grails-1.3.9/plugins/mail-1.0.1
Installed plugin mail-1.0.1 to location /home/blake/.grails/1.3.9/projects/egrants-grails-1.3.9/plugins/mail-1.0.1. ...
Resolving plugin JAR dependencies ...
Plugin mail-1.0.1 installed
Plugin /home/blake/.ivy2/cache/javax.mail/mail/jars/mail-1.4.3.jar is not a valid Grails plugin. No plugin.xml descriptor found!
[delete] Deleting directory /home/blake/.grails/1.3.9/projects/egrants-grails-1.3.9/plugins/constraints-0.6.0
[delete] Deleting directory /home/blake/.grails/1.3.9/projects/egrants-grails-1.3.9/plugins/mail-1.0.1
application.properties
#Grails Metadata file
#Tue May 27 22:06:43 EST 2014
app.grails.version=1.3.9
app.name=XXXX
app.servlet.version=2.4
app.version=1.XXXXX
plugins.codenarc=0.8.1
plugins.constraints=0.6.0
plugins.cxf=0.7.0
plugins.external-config-reload=1.2-SNAPSHOT
plugins.geb=0.4
plugins.gsp-arse=1.3
plugins.hibernate=1.3.9
plugins.jquery=1.8.3
plugins.jquery-ui=1.8.24
plugins.mail=1.0.1
plugins.nerderg-form-tags=1.3
plugins.rendering=0.4.3
plugins.spock=0.5-groovy-1.7
plugins.spring-security-core=1.0.1
plugins.tomcat=1.3.9
and the BuildConfig
// BuildCOnfig.groovy
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
grailsPlugins()
grailsHome()
grailsCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
//mavenLocal()
mavenCentral()
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
mavenRepo "http://repo.grails.org/grails/repo/"
mavenRepo "http://repository.springsource.com/maven/bundles/release"
mavenRepo "http://repository.springsource.com/maven/bundles/external"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.5'
runtime (group:'com.googlecode.ehcache-spring-annotations', name:'ehcache-spring-annotations', version:'1.2.0') {
excludes(
[name: 'ehcache-core'],
[group: 'org.springframework'],
[group: 'org.slf4j']
)
}
}
}
Turns out that letting it automatically resolve dependencies at compile time is a bad idea (TM). Manually installing every required plugin individually seems to have done the trick:
grails install-plugin <plugin> <version>
I am getting failed download error when trying to install new-doc plugin. The error message I get looks like:
==== http://repo.grails.org/grails/libs-releases-local: tried
http://repo.grails.org/grails/libs-releases-local/net/sf/json-lib/json
-lib/2.4/json-lib-2.4.jar
::::::::::::::::::::::::::::::::::::::::::::::
:: FAILED DOWNLOADS ::
:: ^ see resolution messages for details ^ ::
::::::::::::::::::::::::::::::::::::::::::::::
:: net.sf.json-lib#json-lib;2.4!json-lib.jar
::::::::::::::::::::::::::::::::::::::::::::::
| Error Failed to resolve dependencies (Set log level to 'warn' in BuildConfig.groovy for more information):
- net.sf.json-lib:json-lib:2.4
My BuildConfig.groovy looks like:
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.plugins.dir = "plugins"
grails.project.war.file = "target/${appName}.war"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
grailsPlugins()
grailsHome()
grailsCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
//mavenLocal()
mavenCentral()
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
compile 'org.apache.poi:poi:3.9'
compile 'org.apache.poi:poi-ooxml:3.9'
compile 'com.google.guava:guava:12.0'
}
plugins {
compile ":new-doc:0.3.2"
}
}
I am fairly new to groovy/grails so I am not sure what should I do next to resolve this issue. Or can anyone suggest me any other code documentation plugin for grails?
Thanks,
Dee
NOTE
When I ran "grails doc" it generated all the documentation code in target/docs folder. It has index.html page which I thought would list all the api functions, but it didn't have any information on the api documents there - so I wrongly concluded that grails doc was not generating the API documentation. I should have looked into target/docs/gapi folder instead to get the generated API documents for grails. I apologize for my noob problem, and not being able to see the solution that was right there in front of me. Thanks.
I've been racking my brain for hours trying to figure this out. Whenever I try to perform any kind of action to my newly created Grails project (with a fresh Grails install), I get this error message:
Error There was an error loading the BuildConfig: ivy pattern must be absolute:
${HOME}/.m2/alpha/repository/[organisation]/[module]/[revision]/[module]-[revision](-
[classifier]).pom (Use --stacktrace to see the full trace)
I can deduce that there's a problem with my installation, but its a fresh install as I said so I'm not sure what could have caused this problem already.
I'm running Win7. Any help would be much appreciated.
EDIT:
grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenLocal()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.20'
}
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.7.1"
runtime ":resources:1.1.6"
// Uncomment these (or add new ones) to enable additional resources capabilities
//runtime ":zipped-resources:1.0"
//runtime ":cached-resources:1.0"
//runtime ":yui-minify-resources:0.1.4"
build ":tomcat:$grailsVersion"
runtime ":database-migration:1.1"
compile ':cache:1.0.0.RC1'
}
}
Problem solved for now.
It was a Maven problem, which I didn't consider initially. For some reason, the localRepository tag in /Users/USERNAME/.mp2/settings.xml couldn't resolve the path to HOME, so replacing ${HOME} with the C:/Users/USERNAME did the trick. Strange but it works for now. If anyone has a better solution let me know!
My solution was a little different:
(1) Create a variable that points to your .m2 repository location:
def localMavenRepo = "file://" + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
(2) Create a repository entry:
repositories {
...
mavenRepo name: 'Local', root: localMavenRepo
}
I also got the same problem.
I think it's not Maven problem, it's Apache Ivy's problem.
I think Apache Maven 2/3 works well, it's just that Apache Ivy didn't pick the correct Maven folder. The Apache Ivy didn't expand the ${user.home} as it should.
I solved this by setting my M2_REPO environment variable to an absolute path. On linux:
export M2_HOME=/home/chris/.m2/repository/
On windows you can set environment variables in the System Properties dialog (shortcut to System Properties is WindowsKey+PauseKey). Go to System Properties -> Advanced -> Environment Variables.
I'm suffering from grails dependencies with only pom.xml in the jar files at the moment. Basically, I'm trying to use grails dependencies to include neo4j which the main file only contain pom.xml http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22neo4j%22.
This is my BuildConfig.groovy
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.war.file = "target/ROOT.war"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
grailsPlugins()
grailsHome()
grailsCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
mavenLocal()
// mavenCentral()
// mavenRepo "http://m2.neo4j.org/snapshots/"
// flatDir name:'neo4j', dirs:'/lib/neo4j'
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
/*
* Configure our resolver.
*/
// def libResolver = new org.apache.ivy.plugins.resolver.URLResolver()
// ['libraries', 'builds'].each {
// libResolver.addArtifactPattern(
// "/Users/ncharass/.ivy/cache/[artifact]-[revision].[ext]")
//
// }
// libResolver.name = "my-repository"
// libResolver.settings = ivySettings
// resolver libResolver
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
compile 'org.neo4j:neo4j:1.4.1'
// runtime 'mysql:mysql-connector-java:5.1.13'
}
}
It seems to download all the jar files successfully, but those jars only contain pom.xml which it seems that Gradle or Ivy doesn't pick up any pom.xml for any references, so I got complication errors.
I tried almost everything but it doesn't seem to work. Also, the lib that I download from neo4j website also only contains pom.xml.
Please help! :(
Someone already proposed the following on the neo4j mailing list:
repositories {
grailsPlugins()
grailsHome()
grailsCentral()
mavenLocal()
mavenCentral()
flatDir name:'neo4j', dirs:'/${PATH}/lib/neo4j'
}
dependencies {
compile 'org.neo4j:neo4j-kernel:1.4.1'
compile 'org.neo4j:neo4j-cypher:1.4.1'
compile 'org.neo4j:neo4j-graph-algo:1.4.1'
compile 'org.neo4j:neo4j-graph-matching:1.4.1'
compile 'org.neo4j:neo4j-jmx:1.4.1'
compile 'org.neo4j:neo4j-lucene-index:1.4.1'
compile 'org.neo4j:neo4j-shell:1.4.1'
compile 'org.neo4j:neo4j-udc:1.4.1'
compile 'org.neo4j:lucene-core:3.1.0'
compile 'org.neo4j:scala-library:2.9.0-1'
compile 'org.neo4j:server-api:1.4.1'
}
or just use
compile 'org.neo4j:neo4j-community:1.4.1'
in the dependencies section.