Grails not loading classes in .jar file
I am interested in using a certain library (Gremlin, the graph traversal language) in my Grails project. I dropped the necessary .jars into [grailsproject]/lib. But when I do grails run-app
it gives me a compilation error re:a class 'Gremlin' which is part of the jar (I confirmed that it is included in the jar by running tar tf <jarfile>.jar
, and it shows the class Gremlin):
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
...unexpected token: Gremlin @ line 45, column 2.
[groovyc] Gremlin.load()
[groovyc] ^
Is there a way to "refresh" Grails to make sure it loads the new jar files? I use the exact same jar in an independent groovy test app with the same import statements, and there I am able to use the Gremlin class and it works fine. My system $CLASSPATH doesn't include any jar files that I haven't also added in [grailsproject]/lib.
Any ideas?
Thanks!
Update: Here's the relevant section from the code:
package com.mycompany.myproject
import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH
import com.orientechnologies.common.collection.*
import com.orientechnologies.common.*
import com.orientechnologies.orient.core.*
import com.tinkerpop.blueprints.*
import com.tinkerpop.blueprints.pgm.*
import com.tinkerpop.blueprints.pgm.impls.orientdb.*
import com.tinkerpop.gremlin.pipes.*
import com.tinkerpop.gremlin.Gremlin
import co开发者_如何学JAVAm.tinkerpop.gremlin.*
class GraphDbService {
boolean transactional = true
Gremlin.load()
...
I think you have to put Gremlin.load()
inside a method, not just in the definition section of your service class...
ie:
class GraphDbService {
boolean transactional = true
def someServiceMethod() {
Gremlin.load()
}
...
Or, preferably, you should be able to put it in the init()
method of your BootStrap.groovy
file, as it only needs calling once , so that it can decorate all of the required classes.
I think you should be able to add the following to the grails-app/conf/BuildConfig.groovy
grails.project.dependency.resolution = {
//...bunch of stuff
dependencies {
// other resolved dependencies here
compile files('lib/gremlim.jar')
}
}
Do
grails compile --refresh-dependencies
精彩评论