Thursday, April 3, 2014

"<useUniqueVersions>" for pom.xml

If your RPM is building successfully, but when you try to run that component after installing, you get java.lang.NoClassDefFoundError for some class which you know exists in the classpath, then probably the component version (or name) in your Manifest.MF file doesn't match the JAR file included in the classpath (for example MANIFEST.MF expects released version, but classpath contains SNAPSHOT version). In this situation, we can specify in the maven-jar-plugin inside pom.xml not to look for the Unique version of JAR with this tag:

<useUniqueVersions>false</useUniqueVersions>

Complete example:
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
               <execution>
                  <goals>
                     <goal>jar</goal>
                  </goals>
                  <phase>package</phase>
               </execution>
            </executions>
            <configuration>
               <archive>
                  <manifest>
                     <addClasspath>true</addClasspath>
                     <useUniqueVersions>false</useUniqueVersions>
                  </manifest>
               </archive>
            </configuration>
         </plugin>

Now build your rpm and try again, hopefully it fixes it.
For more info: https://maven.apache.org/shared/maven-archiver/examples/classpath.html#aSnapshot