简体   繁体   中英

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 .jar s 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM