Maven exec:java run executable plugin dependency jar results in NPE - 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.
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

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>

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

Related

Migrating AppEngine application to Java 11 runtime - [http://java.sun.com/jsp/jstl/core] cannot be resolved

So I have an AppEngine application that I'm working on migrating to the Java 11 runtime, and am using the appengine-simple-jetty-main artifact, as outlined in https://cloud.google.com/appengine/docs/standard/java-gen2/war-packaging, to replace the built-in Jetty server of the old Java 8 runtime.
Now if I use mvn jetty:run to bring up my application locally, everything works fine. But when I try to run the appengine-simple-jetty-main wrapper via mvn exec:java -Dexec.args="<my application directory>/target/<application>.war", I hit an issue.
The server starts up fine, and executes various ServletContextListeners that use outside dependencies declared in my pom.xml. I'm also able to navigate to static HTML. When I try to navigate to a JSP Servlet, however, I'm getting the error
HTTP ERROR 500 org.apache.jasper.JasperException: The absolute uri: [http://java.sun.com/jsp/jstl/core] cannot be resolved in either web.xml or the jar files deployed with this application
And likewise, I get this same error when I actually deploy to AppEngine.
As mentioned before, this works just fine when I bypass appengine-simple-jetty-main wrapper using mvn jetty:run, and my pom.xml includes the dependency
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>2.0.0</version>
</dependency>
My build section looks like
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>11.0.11</version>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<deploy.projectId>contra-program</deploy.projectId>
<deploy.version>GCLOUD_CONFIG</deploy.version>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/appengine-staging</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
So I'm a bit flummoxed. Other maven dependencies seem to be getting brought in just fine. It's only the JSTL library that's having issues (so far, at least), and even then, only when I use the appengine-simple-jetty-main wrapper.
The nearest existing question I could find was cannot load JSTL taglib within embedded Jetty server, but I haven't had luck with the provided solutions (though I'm more than happy to admit the possibility that I'm just not applying one or more of them correctly).
Any pointers would be greatly appreciated :-)

swagger-codegen-maven-plugin best practices

I'm using the swagger-codegen-maven-plugin within my pom to generate a client. Here is my plugin info:
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.9</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.json</inputSpec>
<language>java</language>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Using:
java version "1.8.0_221"
Apache Maven 3.6.1
I had many errors when running mvn compile, as the package names could not be found in my repo e.g.
[ERROR]
//target/generated-sources/swagger/src/main/java/io/swagger/client/model/.java:[18,23]
package com.google.gson does not exist
To overcome the errors and enable a successful mvn compile, I have had to name the missing packages within my pom's dependencies e.g.
<dependencies>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
I don't believe this is best practice, as I have to specify the version myself without knowing the actual version that the source has used.
My question is, what is the best practice for generating a client using maven when there are packages which can't be resolved by the swagger-codegen-plugin? Alternatively, please advise if the resolution I have found to overcome the issue is actually the best practice in this scenario?
Thanks.

Failed to execute goal (generate-scr-scrdescriptor) on project Unable to load compiled class

Have any one faced below error. why it causes.? am using the below version of plugins.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.20.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
<configuration>
<!-- Private service properties for all services. -->
<properties>
<service.vendor>Adobe</service.vendor>
</properties>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.5.11</version>
</dependency>
</dependencies>
</plugin>
[ERROR] Failed to execute goal
org.apache.felix:maven-scr-plugin:1.20.0:scr
(generate-scr-scrdescriptor) on project osgiexample.core:
E:\MY-Work\TESTProj\osgiexample\core\src\main\java\osgiexample\core\servlets\MyDataProviderServlet.java
: Unable to load compiled class:
osgiexample.core.servlets.MyDataProviderServlet -> [Help 1]
This means that the SCR plugin is unable to find a compiled class file corresponding to the file MyDataProviderServlet.java
I've only seen this happen in the following situations:
I had special characters in the path to my project, which caused the SCR plugin to fail to find the compiled classes.
I had a *.java file but its contents were temporarily commented out. The SCR plugin expected to find a compiled *.class file but there was nothing to compile (just comments). This caused an error message exactly like the one you saw.
Off the top of my head, I can't think of other cases where a class file would not be found by the SCR plugin without the Compiler plugin failing first.
I'd look for something unusual in the Java class itself. Does this happen for other classes with SCR annotations or just this one?
As a next step, I'd look at the file system. Could be a strange character or a file link confusing the plugin.
Finally, I'd inspect the rest of the Maven build. Perhaps you're using other plugins that might remove or otherwise mangle the class file prior to the SCR Plugin's execution?

maven/apt generated classes in eclipse

Using following configuration in master pom, some classes (metamodel FYI) are generated for all child projects having jpa entities under target/generated-sources, as expected.
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.10.Final</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
This works perfectly from Maven and Netbeans.
Some team members still use Eclipse. There, generated classes aren't found automatically. They can be opened if added manually to the "build path" (whatever it means as this is redundant to pom.xml). However, that's not stable and will be reset whenever they "update the project" (shouldn't even be needed but...) to reflect project's maven configuration.
My question is, how to configure Eclipse to use this project's configuration automatically? I don't want to change the project's pom.xml too much, as they are perfectly legal and work well outside of Eclipse, which I just want to be taught to behave correctly.
UPDATE: M2Eclipse is installed and doesn't solve this, which is basically our problem.
There ist a project/Eclipse-Plugin called M2Eclipse (link).
The plugin includes the following feature:
Dependency management for Eclipse build path based on Maven's pom.xml

JUnit tests fail with Java error when using IntelliJ within maven module after adding Hibernate Metamodel classes

On my project we've used Hibernate's (JPA) Metamodel Generator to make our Criteria queries type safe. It all works great within our app, however, when we run the JUnit tests within that Maven module using our IDE they now fail with the following error:-
Error:java: Annotation processor 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' not found
Which I guess is due to the following in our generated classes:-
#Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
#StaticMetamodel(MyEntity.class)
When Maven runs the tests as part of our build process then they run with no problems at all.
I suspect I'm missing something within the set up of my IDE, which is IntelliJ IDEA 14. Any ideas what this might be? Or have I done something wrong within Maven? :-
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.4.Final</version>
<optional>true</optional>
</dependency>
</dependencies>
</plugin>
I had a similar problem after I upgraded to IntelliJ IDEA 14.1.2. For me the following action resolved the problem:
Go to Settings > Build, Execution, Deployment > Compiler > Annotation Processors.
On the left of this configuration panel I have an Annotation profile for every maven module in my project. I did not set up these profiles myself: maybe they where inferred by the IDE. I don't know, but in some of these annotation profiles, the enable annotation processing flag was enabled. Moreover, in some cases, the JPAMetaModelEntityProcessor was explicitly listed here as an annotation processor. After removing the annotation processor from the profile and disabling the checkbox, the error disappeared and my test ran successfully.
The answer by #Jeroen Noels disables annotation processing in IDEA.
To keep it enabled I've added
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.4.Final</version>
<scope>provided</scope>
</dependency>
to the Maven dependencies, i.e. to the classpath. Note that the scope is provided!

Resources