名称为“BlockTreeOrds”的Neo4j 3.0.x PostingsFormat不存在

时间:2016-06-13 18:53:09

标签: neo4j

我尝试从Neo4j 2.3更新到3.0.1。我可以将数据库作为服务启动,没问题。

但是当我尝试构建一个Neo4j可执行文件并运行它时,我发现了一个我无法解决的错误。在Neo4j 2.x下,我可以构建可执行文件。以下是我的主要方法:

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

我有一个简单的POM,有1个依赖: <dependencies> <dependency> <groupId>org.neo4j</groupId> <artifactId>neo4j</artifactId> <version>3.0.1</version> </dependency> </dependencies>

命令行参数分别是我的数据库和配置的路径。 下面是此图实例化错误的堆栈跟踪。

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

由于我可以使用“bin / neo4j”将数据库作为服务启动,我认为/neo4j-community/3.0.1/lib下的文件与Maven提供的文件之间必然存在差异。我试过用java -cp“/neo4j-community/3.0.1/lib/*”运行我的可执行文件无济于事。任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:6)

最可能的原因是Maven没有将Lucene jar文件的META-INF/services包含在已编译的工件中:

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

如您所见,这是定义BlockTreeOrdsPostingsFormat的地方。

您可以通过创建shaded jar with a ServicesResourceTransformer来解决问题,该MSDN Documentation会将所有包含的jar文件中的所有各种META-INF/services合并在一起。

        <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 :(得分:1)

您的maven依赖还不够,请将其更改为

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

更新

也许添加这个可以解决它:

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

答案 2 :(得分:1)

这可能是编码问题吗? 我的构建目前显示完全相同的行为。 它在eclipse中运行得很好但是构建一个jar文件会丢失这个错误。

我的src文件以utf8和所有资源编码。 我注意到db本身以及compilations和jar将是ANSI。

创建数据库时工作正常。在它上面使用交易将完全失败。 我进一步注意到使用eclipse我没有charset问题但是从power shell执行jar会显示错误的字符。 我还发现了一个nullpointer异常,在db中查找节点时不应该有。

所有强有力的指标都认为这可能是编码问题,因为构建文件本身看起来完美无瑕。

遗憾的是,将我的所有文件转换为ansi只是为了看看我的预感是否正确,但这可能会有所帮助。