Maven exec:java在NPE中运行可执行插件依赖项jar结果 [英] Maven exec:java run executable plugin dependency jar results in NPE
问题描述
我正在制作一个使用sparql端点服务的Maven应用程序.我想要一个maven目标来下载sparql端点并启动服务,但是看来maven在配置类路径时遇到了一些问题.
I'm making a maven application that uses a sparql endpoint service. I'd like to have a maven goal to download the sparql endpoint and start the service but it seems that maven have some problems to configure the classpath.
我在 https://mvnrepository.com/上使用blazegraph及其工件artifact/com.blazegraph/bigdata-jar .
这是pom.xml中我的插件配置:
Here it is my plug-in configuration in 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>
debug输出提示插件找不到工件:
The debug output hints that the plug-in can't find the artifact:
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 这个问题与什么是NullPointerException无关,以及我该如何解决?因为Maven抛出了异常,因为它在依赖项列表中找不到正确的工件(但应该如此).
Edit 1 This question is not a duplicate of What is a NullPointerException, and how do I fix it? because the exception is thrown by Maven since it can't find the right artifact in the list of dependencies (but it should).
编辑2 感谢@Sean Patrick Floyd,我已部分解决了该问题.我猜类路径配置中仍然存在一些问题.现在,Maven找到了主类和jar,但是执行后,我在编译代码中得到了另一个NPE.在blazegraph的开源代码中,看来它无法在可执行jar中打开资源.
Edit 2 Thanks to @Sean Patrick Floyd I've partially solved the issue. There are still some problem in the classpath configuration, I guess. Now Maven finds the main class and the jar but after the execution I get an other NPE in compiled code. Looking in the open source code of blazegraph it seems that it can't open a resource inside the executable jar.
以下是引起NPE的行:
Here is the line that causes NPE:
System.setProperty("jetty.home",
jettyXml.getClass().getResource("/war").toExternalForm());
推荐答案
< executableDependency>
机制用于二进制文件,而不用于JAR,即
The <executableDependency>
mechanism is used for binaries, not for JARs, see the usage page. Remove that part, these settings should be sufficient:
<mainClass>com.bigdata.rdf.sail.webapp.StandaloneNanoSparqlServer</mainClass>
<includePluginDependencies>true</includePluginDependencies>
这篇关于Maven exec:java在NPE中运行可执行插件依赖项jar结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!