2
votes

I tried updating from Neo4j 2.3 to 3.0.1. I can start up the database as a service, no problem there.

But when I try to build a Neo4j executable and run it, I find a bug which I cannot resolve. Under Neo4j 2.x I can build executables fine. Below is my main method:

public class StartDB {
    public static void main(String[] args) {
        new GraphDatabaseFactory()
        .newEmbeddedDatabaseBuilder(Paths.get(args[0]).toFile())
        .loadPropertiesFromFile(args[1])
        .newGraphDatabase();
    }
}

I have a simple POM with 1 dependency: <dependencies> <dependency> <groupId>org.neo4j</groupId> <artifactId>neo4j</artifactId> <version>3.0.1</version> </dependency> </dependencies>

The command line arguments are the paths to my DB and config respectively. Below is the stacktrace from this graph instantiation error.

Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.CommunityFacadeFactory, /home/glemmon/UPDB/data/neo4j-3.0.1/data/databases/graph.db
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:144)
    at org.neo4j.kernel.impl.factory.CommunityFacadeFactory.initFacade(CommunityFacadeFactory.java:40)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:108)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:99)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$206(GraphDatabaseFactory.java:88)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory$$Lambda$1/1313922862.newDatabase(Unknown Source)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183)
    at test.StartDB.main(StartDB.java:11)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine@5483163c' failed to initialize. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:415)
    at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:98)
    at org.neo4j.kernel.NeoStoreDataSource.start(NeoStoreDataSource.java:502)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
    at org.neo4j.kernel.impl.transaction.state.DataSourceManager.start(DataSourceManager.java:99)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:140)
    ... 7 more
Caused by: java.lang.IllegalArgumentException: An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'BlockTreeOrds' does not exist.  You need to add the corresponding JAR file supporting this SPI to your classpath.  The current classpath supports the following names: [Lucene50]
    at org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:114)
    at org.apache.lucene.codecs.PostingsFormat.forName(PostingsFormat.java:112)
    at org.apache.lucene.codecs.perfield.PerFieldPostingsFormat$FieldsReader.<init>(PerFieldPostingsFormat.java:258)
    at org.apache.lucene.codecs.perfield.PerFieldPostingsFormat.fieldsProducer(PerFieldPostingsFormat.java:341)
    at org.apache.lucene.index.SegmentCoreReaders.<init>(SegmentCoreReaders.java:104)
    at org.apache.lucene.index.SegmentReader.<init>(SegmentReader.java:65)
    at org.apache.lucene.index.ReadersAndUpdates.getReader(ReadersAndUpdates.java:145)
    at org.apache.lucene.index.ReadersAndUpdates.getReadOnlyClone(ReadersAndUpdates.java:197)
    at org.apache.lucene.index.StandardDirectoryReader.open(StandardDirectoryReader.java:99)
    at org.apache.lucene.index.IndexWriter.getReader(IndexWriter.java:435)
    at org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:100)
    at org.apache.lucene.search.SearcherManager.<init>(SearcherManager.java:106)
    at org.apache.lucene.search.SearcherManager.<init>(SearcherManager.java:76)
    at org.neo4j.kernel.api.impl.index.partition.IndexPartition.<init>(IndexPartition.java:54)
    at org.neo4j.kernel.api.impl.index.AbstractLuceneIndex.open(AbstractLuceneIndex.java:101)
    at org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProvider.indexIsOnline(LuceneSchemaIndexProvider.java:178)
    at org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProvider.getInitialState(LuceneSchemaIndexProvider.java:123)
    at org.neo4j.kernel.impl.api.index.IndexingService.init(IndexingService.java:200)
    at org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine.init(RecordStorageEngine.java:403)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:405)
    ... 16 more

Since I can start the DB as a service using "bin/neo4j", I thought there must be a discrepancy between the files under /neo4j-community/3.0.1/lib and the files Maven is providing. I've tried running my executable with java -cp "/neo4j-community/3.0.1/lib/*" to no avail. Any help would be appreciated.

3
Was this ever resolved? I'm having the same issue.ghstcode
Nope. I still am unable to run my code :(Gordon Lemmon

3 Answers

6
votes

The most likely reason is that Maven is not including the Lucene jar file's META-INF/services into the compiled artifact:

META-INF/services/org.apache.lucene.codecs.PostingsFormat

org.apache.lucene.codecs.blocktreeords.BlockTreeOrdsPostingsFormat
org.apache.lucene.codecs.bloom.BloomFilteringPostingsFormat
org.apache.lucene.codecs.memory.DirectPostingsFormat
org.apache.lucene.codecs.memory.FSTOrdPostingsFormat
org.apache.lucene.codecs.memory.FSTPostingsFormat
org.apache.lucene.codecs.memory.MemoryPostingsFormat
org.apache.lucene.codecs.simpletext.SimpleTextPostingsFormat
org.apache.lucene.codecs.autoprefix.AutoPrefixPostingsFormat

As you can see, this is where the BlockTreeOrdsPostingsFormat is defined.

You can work round the problem by creating a shaded jar with a ServicesResourceTransformer, which will merge all the various META-INF/services from all the included jar files together.

        <plugin>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>

                            <!-- add Main-Class to manifest file -->
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>...</mainClass>
                            </transformer>

                            <!-- merge META-INF/services -->
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
1
votes

Your maven dependency is not sufficient, change it to

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-community</artifactId>
    <version>3.0.1</version>
    <type>pom</type>
</dependency>

update

maybe adding this one solves it:

<dependency>
    <groupId>org.apache.lucene</groupId>
    <artifactId>lucene-codecs</artifactId>
    <version>5.5.0</version>
</dependency>
1
votes

could this be an encoding issue? my build currently shows the exact same behavior. it runs perfectly fine in eclipse but building a jar file drops this error.

my src files are encoded in utf8 as well as all the resources. I noticed that the db itself and the compilations and jar will be ANSI though.

while creating the database works fine. using transactions on it will utterly fail. I further noticed that using eclipse i have no charset issues but executing the jar from power shell will display faulty characters. I also found a nullpointer exception where there shouldn't have been one when looking up a node in the db.

all strong indicators that this might be an encoding issue as the build file itself looks flawless.

sadly it would be quite an effort to convert all my files to ansi just to see if my hunch was correct but maybe this was of help.