null pointer exception at startup
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at application.APSApplication.main(APSApplication.java:34)
The error occurs when reading the artifact version out of the generated jar file. While builds of older versions of Maven work properly, builds of the newer Maven version (3.6.1) will fail. The reason is a different structure within the jar-file.
However it seems that there is a version independent way to achieve the same goal, see: https://stackoverflow.com/questions/2712970/get-maven-artifact-version-at-runtime
When using the solution 1:1 it doesn't work, as entries in the MANIFEST are still not generated, because we are using the maven-assembly-plugin
instead of the maven-jar-plugin
. Thus the configurations have to be moved to the right plugin, resulting in the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>application.APSApplication</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
Then we can just use:
SdcLogger.log.info("MoVE Abstract Provider Simulator (APS) - Version: " + APSApplication.class.getPackage().getImplementationVersion());
This solution works for me with Maven v3.6.1 and v3.6.2 (latest)