我正在制作一个使用 sparql 端点服务的 Maven 应用程序。我想要一个 Maven 目标来下载 sparql 端点并启动服务,但似乎 Maven 在配置类路径方面存在一些问题。
我正在使用 blazegraph 及其工件https://mvnrepository.com/artifact/com.blazegraph/bigdata-jar https://mvnrepository.com/artifact/com.blazegraph/bigdata-jar.
这是我在 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
我缺少什么?
Edit 1这个问题不是重复的什么是 NullPointerException,如何修复它? https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it因为 Maven 会抛出异常,因为它无法在依赖项列表中找到正确的工件(但应该如此)。
Edit 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 https://github.com/blazegraph/database/blob/master/bigdata-jar/src/main/java/com/bigdata/rdf/sail/webapp/StandaloneNanoSparqlServer.java#L142