Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 218
Cristiano Avatar asked Jun 07 '17 10:06

Cristiano


People also ask

What does Mvn exec exec do?

Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process. exec:java - can be used to run a Java program in the same VM.

What is Mvn exec Java?

mvn exec:java is a goal from the exec plugin for maven. It lets you specify a main class to execute (see pom. xml). This lets you avoid having to figure out the proper java command to run and classpath arguments and the like.

What is the correct syntax for executing a maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”. For example mvn example:version .

What is exec Java?

exec(String command) method executes the specified string command in a separate process. This is a convenience method. An invocation of the form exec(command) behaves in exactly the same way as the invocation exec(command, null, null).


1 Answers

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>
like image 127
Sean Patrick Floyd Avatar answered Sep 18 '22 11:09

Sean Patrick Floyd