我正在制作一个使用sparql端点服务的Maven应用程序。我想要一个maven目标来下载sparql端点并启动服务,但是看来maven在配置类路径时遇到了一些问题。
我在https://mvnrepository.com/artifact/com.blazegraph/bigdata-jar使用blazegraph及其工件。
这是pom.xml中我的插件配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.bigdata.rdf.sail.webapp.StandaloneNanoSparqlServer</mainClass>
<includePluginDependencies>true</includePluginDependencies>
<includeProjectDependencies>false</includeProjectDependencies>
<executableDependency>
<groupId>com.blazegraph</groupId>
<artifactId>blazegraph-jar</artifactId>
</executableDependency>
<addOutputToClasspath>false</addOutputToClasspath>
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.blazegraph/blazegraph-jar -->
<dependency>
<groupId>com.blazegraph</groupId>
<artifactId>blazegraph-jar</artifactId>
<version>2.1.4</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
调试输出提示插件找不到工件:
Caused by: java.lang.NullPointerException
at org.codehaus.mojo.exec.AbstractExecMojo.findExecutableArtifact(AbstractExecMojo.java:278)
at org.codehaus.mojo.exec.ExecJavaMojo.determineRelevantPluginDependencies(ExecJavaMojo.java:650)
at org.codehaus.mojo.exec.ExecJavaMojo.addRelevantPluginDependenciesToClasspath(ExecJavaMojo.java:568)
at org.codehaus.mojo.exec.ExecJavaMojo.getClassLoader(ExecJavaMojo.java:520)
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:301)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 27 more
我想念什么?
编辑1
这个问题不是What is a NullPointerException, and how do I fix it?的重复,因为Maven抛出了异常,因为它在依赖项列表中找不到正确的工件(但应该如此)。
编辑2
感谢@Sean Patrick Floyd,我已部分解决了该问题。我想类路径配置中仍然存在一些问题。现在,Maven找到了主类和jar,但是执行之后,我在编译代码中得到了另一个NPE。在blazegraph的开源代码中,似乎无法打开可执行jar内的资源。
这是导致NPE的行:
System.setProperty("jetty.home",
jettyXml.getClass().getResource("/war").toExternalForm());
https://github.com/blazegraph/database/blob/master/bigdata-jar/src/main/java/com/bigdata/rdf/sail/webapp/StandaloneNanoSparqlServer.java#L142
最佳答案
<executableDependency>
机制用于二进制文件,而不用于JAR see the usage page。删除该部分,这些设置就足够了:
<mainClass>com.bigdata.rdf.sail.webapp.StandaloneNanoSparqlServer</mainClass>
<includePluginDependencies>true</includePluginDependencies>
关于maven - Maven exec:java在NPE中运行可执行插件依赖项jar结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44409624/