Groovy Gremlin from Java project

850 views
Skip to first unread message

Luke Evans

unread,
Oct 2, 2013, 1:43:14 PM10/2/13
to gremli...@googlegroups.com
Hello, 

I would like to have a Groovy class for Titan graph algorithms mixed in with my Java project, but I'm running into an issue. I have tried following this guide: https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Groovy

Here is my Groovy class:
import com.tinkerpop.blueprints.Graph
import com.tinkerpop.blueprints.Vertex
import com.tinkerpop.gremlin.groovy.Gremlin
class GraphAlgorithms {
static {
    Gremlin.load()
//================================================================================
// Example
//================================================================================
public static Map<Vertex, Integer> eigenvectorRank(Graph g) {
    Map<Vertex,Integer> m = [:]; int c = 0
    g.V.as('x').out.groupCount(m).loop('x') {c++ < 1000}.iterate()
    return m
}

My pom.xml has the following:

<dependency>
    <groupId>com.thinkaurelius.titan</groupId>
    <artifactId>titan-cassandra</artifactId>
    <version>0.3.2</version>
</dependency> 
<dependency>
    <groupId>com.thinkaurelius.titan</groupId>
    <artifactId>titan-core</artifactId>
    <version>0.3.2</version>
</dependency> 
<dependency>
    <groupId>com.tinkerpop.gremlin</groupId>
    <artifactId>gremlin-java</artifactId>
    <version>2.4.0</version>
</dependency> 
<dependency>
    <groupId>com.tinkerpop.gremlin</groupId>
    <artifactId>gremlin-groovy</artifactId>
    <version>2.4.0</version>
</dependency> 
<dependency>
    <groupId>com.tinkerpop.blueprints</groupId>
    <artifactId>blueprints-core</artifactId>
    <version>2.4.0</version>
</dependency> 
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy</artifactId>
    <version>2.1.7</version>
</dependency> 
<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>groovy-maven-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId
            <version>2.0.6</version>
       </dependency>
    </dependencies>
</plugin>

The issue arises on the call Gremlin.load, and I get the stack trace: 


java.lang.ClassNotFoundException: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at com.tinkerpop.gremlin.groovy.Gremlin.class$(Gremlin.groovy)
    ...

 Thinking it could be a Gremlin Groovy Script Engine error, I tried adding the line: com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFactory to my META-INF/services/javax.script.ScriptEngineFactory but this didn't seem to help.

If anyone knows where I could be going wrong, I would greatly appreciate some insight! 
-Luke

Stephen Mallette

unread,
Oct 2, 2013, 2:05:18 PM10/2/13
to gremli...@googlegroups.com
Not sure if this is your issue or not, but your pom.xml snippet shows dependency on groovy 2.1.7, but gremlin-groovy supports 1.8.9.  You definitely have some conflicts there.  Perhaps that is the root of your problem.

Stephen


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Daniel Kuppitz

unread,
Oct 2, 2013, 2:18:52 PM10/2/13
to gremli...@googlegroups.com
Working example: https://github.com/dkuppitz/GremlinGroovyJava

Cheers,
Daniel


2013/10/2 Luke Evans <leva...@gmail.com>

--

Stephen Mallette

unread,
Oct 2, 2013, 2:38:28 PM10/2/13
to gremli...@googlegroups.com
It may work on the surface, but is it a good idea to include groovy 2.x?


I'm not so sure it is...........

Stephen

fancyerii

unread,
Sep 3, 2014, 10:13:11 PM9/3/14
to gremli...@googlegroups.com
it works. Do you know how to compile and run in eclipse? I am used to eclipse to write codes.
I use mvn eclipse:eclipse and import it to eclipse, But the App class can't find GroovyGraphAlgorithms.
I also use eclipse-groovy plugin to convert it to groovy project. the groovy file is correctly compiled. but java class can't find it.

Bob B

unread,
Sep 4, 2014, 7:17:11 AM9/4/14
to gremlin-users

I didn't look too closely at Daniel's super awesome example project so he might correct me but...

It looks like the groovy folder (src/main/groovy/)  is not picked up as a source directory. 

Bob

fancyerii

unread,
Sep 5, 2014, 12:14:57 AM9/5/14
to gremli...@googlegroups.com
I solved this problem by add src/main/groovy a filter **/*.groovy
Reply all
Reply to author
Forward
0 new messages