Cristiano
Cristiano

Reputation: 556

Maven exec:java run executable plugin dependency jar results in NPE

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

Upvotes: 6

Views: 3133

Answers (2)

Abdullah Shahin
Abdullah Shahin

Reputation: 1052

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

Upvotes: 2

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298858

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>

Upvotes: 13

Related Questions