1

I would like to configure Titan Db using the API. I have created a Groovy script like so...

import static com.thinkaurelius.titan.core

Then on the command line...

bin/groovy -cp  "/Users/Ian/titan/lib/:titan-core-0.5.0.jar"   "../webstormprojects/project1/titan.groovy"

Then...

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /Users/Ian/WebstormProjects/project1/titan.groovy: 1: unable to resolve class com.thinkaurelius.titan @ line 1, column 1. import static com.thinkaurelius.titan.core ^

1 error

What am I doing wrong?

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189

2 Answers2

1

I never use the titan api, however looking at titan-core source on github the com.thinkaurelius.titan.core it's not a class, it's a package, so if you want to import all the classes in that package you have to use .*, also the static modifier imports the static members of the classes so if you want to use the classes not only the static members do:

import com.thinkaurelius.titan.core.*

Instead of:

import static com.thinkaurelius.titan.core

Alternatively if you want to import a specific class in this package, add it to the import, for example if you want to add Titan class:

import com.thinkaurelius.titan.core.Titan

For more information about static modifier you can take a look at this answer.

Hope this helps,

Community
  • 1
  • 1
albciff
  • 18,112
  • 4
  • 64
  • 89
  • Sounds closer but it didn't make the program run. How do you create an index without the API? – Ian Warburton Jan 29 '15 at 21:30
  • 1
    I just downloaded the jar and try `import com.thinkaurelius.titan.core.*` without `static` and works without errors – albciff Jan 29 '15 at 21:38
  • @IanWarburton sorry I don't understand your comment. What did you mean? – albciff Jan 29 '15 at 21:46
  • You say you never use the API but as far as I can make out its needed in order to create indexes. So how would you make an index? – Ian Warburton Jan 29 '15 at 21:47
  • @IanWarburton sorry English language it's not my strength... I just take a look on the `github` for the source code, download the zip with all jars, create a groovy script with your `import` and make a try to verify that not error is thrown, that`s all. Is this what you're asking? – albciff Jan 29 '15 at 21:53
  • Yes you have answered my question. But in your answer you said that you never use the API. How can you not use it? – Ian Warburton Jan 29 '15 at 21:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/69853/discussion-between-albciff-and-ian-warburton). – albciff Jan 29 '15 at 21:55
0

For any one as clueless as me this is what I have done:

1) Download Groovy 2) Create a text file. For example...

import com.thinkaurelius.titan.core.*
import com.thinkaurelius.titan.core.titan.*

TitanGraph graph = TitanFactory.open("/Users/Ian/titan/conf/titan-cassandra-es.properties");

m = graph.getManagementSystem()

m.commit()

graph.shutdown()

You can see I have some class references to the API and I've connected to the database using the config file that was installed with the Titan distribution I downloaded from the website.

You need the graph.shutdown() else the console blocks. Although the documentation makes it sound like this shuts down the entire database. But it only seems to close the connection.

3) From the command line...

bin/groovy -cp  "../titan/lib/*" "../webstormprojects/myproject/titan.groovy"

The class path is set to the lib folder in my Titan instillation folder. The * includes all the packages.

And now hopefully I'm all set to add some indexes. Be aware that the Titan API has been through some significant changes so some of the online info is out of date. This is quite helpful.

Here is the latest documentation.

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189