我创建了一个neo4j用户定义的过程。它还在neo4j中编译和工作。
最近,我在我的程序插件中添加了一个依赖项,当我尝试运行新构建的jar时,它会阻止neo4j启动。具体来说,我在堆栈跟踪的底部收到以下异常:
Caused by: java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
我唯一改变的是将MapDB添加到我的依赖项中。所以我怀疑它取决于一些签名的工件。事实证明,neo4j插件是“uber-jars”(即阴影罐),它与签名的依赖关系不能很好地工作。
我想我可以尝试通过将范围更改为provided
并将mapdb jar添加到neo4j的plugins文件夹中,从阴影中排除MapDB。所以neo4j的plugins文件夹现在包括mapdb.jar
和myprocedure.jar
。
这似乎不起作用:neo4j启动,但在调用我的程序时,我收到ClassNotFound
异常。
关于如何解决这个困境的任何想法?我真的依赖像MapDB这样的东西,因为我的图形非常大并且在我的程序内存中保留所有内容会导致内存异常。
提前谢谢了!
我的pom.xml
的重要部分应该有所帮助(我开始使用procedure template所以它看起来仍然非常相似):
<dependencies>
<!-- other dependencies that don't make a difference ... -->
<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>
<version>3.0.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>${neo4j.version}</version>
<scope>provided</scope>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>${neo4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>1.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<!-- Neo4j Procedures require Java 8 -->
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<!-- This generates a jar-file with our procedure code,
plus any dependencies marked as `compile` scope.
This should then be deployed in the `plugins` directory
of each Neo4j instance in your deployment.
After a restart, the procedure is available for calling. -->
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
因此,一个有效的解决方案是使用maven-assembly-plugin
而不是maven-shade-plugin
。程序集插件创建一个包含所有依赖项的独立jar,而无需重新打包所有依赖项。
当然,我不得不删除mapdb的<scope>provided</scope>
,因此它也包含在已组装的jar中。
其余的只是用以下片段替换树荫插件(感谢这个question here):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
之后我收到另一个例外,我认为是由于错误的签名:
Caused by: java.lang.VerifyError ...
事实证明这只是因为我在neo4j中有另一个使用与mapdb相同依赖的过程。快速修复是删除该过程库。
当然,还有其他解决方案,包括删除签名或重新签名。但是,我明确地不想删除任何签名。
我不知道neo4j默认检查任何jar签名。我怀疑mapdb工件的重新打包是罪魁祸首。
要验证这一点,请删除阴影或程序集插件,并构建一个仅包含代码的jar。将该jar和mapdb.jar复制到plugin文件夹中,并在重新启动时观察日志。