Pavlus
Pavlus

Reputation: 1711

Maven NAR plugin + Spring boot in webapp, loading .nar artifact in Tomcat

I've managed to add platform dependencies to war and generated by maven-nar-plugin jni artifact into WEB-INF/lib/.

But the problem is: added artifact has .nar extension while WebappClassLoaderBase adds only .jars to its internal class repositories, so my jni bridge is not loaded and class is inaccessible leading to ClassNotFoundException.

What are my options here? I assume it's possible to

  1. somehow change artifact extension on spring-boot:repackage?
  2. add this custom artifact to classloader repositories?

Which would be better and how would I implement it?

Upvotes: 0

Views: 86

Answers (1)

Pavlus
Pavlus

Reputation: 1711

Ok, so I've ended up with maven-dependency-plugin:

<build>
...
<plugins>
  <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <executions>
       <execution>
         <goals>
           <goal>copy</goal>
         </goals>
         <configuration>
           <artifactItems>
             <artifactItem>
               <groupId>${dep.groupId}</groupId>
               <artifactId>${dep.artifactId}</artifactId>
               <version>${dep.version}</version>
               <type>nar</type>
               <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
               <destFileName>${dep.artifactId}-${dep.version}.jar</destFileName>
             </artifactItem>
           </artifactItems>
         </configuration>
       </execution>
     </executions>
  </plugin>
  ...
</plugins>
</build>

But still, there is a problem with redeployments to deal with, so if you realy want to do this, here is the way, but you probably don't need it that hard.

Upvotes: 0

Related Questions