-
Notifications
You must be signed in to change notification settings - Fork 237
Using Gremlin through Groovy
okram edited this page Feb 7, 2011
·
36 revisions
Gremlin works by using the metaprogramming facilities provided by Groovy. There is single Groovy class called Gremlin.groovy. To use Gremlin while in Groovy, simply do Gremlin.load() (be sure Gremlin is in the classpath).
Gremlin shell (gremlin.sh) is basically the Groovy shell| wrapped to have the Gremlin look and feel. For example, do \h at the gremlin> prompt.
marko:~$ groovysh
Groovy Shell (1.7.2, JVM: 1.6.0_22)
Type 'help' or '\h' for help.
-------------------------------------------------------------------------------
groovy:000> com.tinkerpop.gremlin.Gremlin.load()If you are using Groovy classes, its trivial to access Gremlin. In this way, your Java code and your Gremlin/Groovy code seamless interact through standard class mechanisms.
class SimpleExample {
public List exampleMethod() {
Gremlin.load()
Graph g = TinkerGraphFactory.createTinkerGraph()
def results = []
g.v(1).outE.inV >> results
return results;
}
}If you build with Maven2, here are some useful snippets that you can add to your pom.xml
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.7.5</version>
</dependency>
<!-- PROJECT BUILDING WITH GROOVY/JAVA -->
<dependency>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
</dependency>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>