6

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.

I'm using blazegraph and its artifact at https://mvnrepository.com/artifact/com.blazegraph/bigdata-jar.

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>

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

What am I missing?

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).

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.

Here is the line that causes 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

Cristiano
  • 534
  • 6
  • 21
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) –  Jun 07 '17 at 13:20
  • 1
    NPE is thrown by a Maven plugin, not OP code. – LoganMzz Jun 07 '17 at 13:26

2 Answers2

13

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>
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • It is also supposed to work with `java` goal: http://www.mojohaus.org/exec-maven-plugin/examples/example-exec-using-plugin-dependencies.html – LoganMzz Jun 07 '17 at 13:29
  • @LoganMzz perhaps. but that can also be a glitch of the maven parameter documentation system. either way, it should work without this. – Sean Patrick Floyd Jun 07 '17 at 13:30
  • Thank you that partially solves the problem. I'm updating the question with new information. – Cristiano Jun 07 '17 at 14:04
1

just wanted to post this here as it fixed my issue and nothing else did, downgrade the version to 1.5.0 worked for me on exec:java for the same plugin configs posted in the question, inspired by the issue https://github.com/mojohaus/exec-maven-plugin/issues/76

Abdullah Shahin
  • 1,002
  • 15
  • 19