Build a MSVC DLL with JNI headers generated by javah

The example uses javah to generate native header files which are then be part of the native build to create a Windows DLL

Note:

  • User is responsible to provide all neccessary compiler and linker options
  • envFactoryName is used to set up compiler and linker specific environments. This feature is extremely useful when you need to use various compilers in your build system and it is impossible to set up single global environment to accomodate all compilers.
  • Checkout real examples in svn
<project>
   ...
   <packaging>dll</packaging>
   
   <dependencies>
     <dependency>
       your jar which has jni interface.
     </dependency>
     <dependency>
       other native library ( .lib, .so, .a, .o, etc)
       to be linked in.
     </dependency>
     ...
   </dependencies>
   
   ...

   <build>
      <!-- The global source and test directory are used -->
      <sourceDirectory>src</sourceDirectory>
      <testSourceDirectory>test</testSourceDirectory>
     <plugins>
       <plugin>
         <groupId>org.jfrog.jade.plugins</groupId>
         <artifactId>jade-native-plugin</artifactId>
         <extensions>true</extensions>
         <configuration>
         
           <compilerProvider>msvc</compilerProvider>
           
           <!-- setup compiler and linker environment according to msvc 6 vcvars32.bat -->
           <!-- without this setting, you will need to setup the environment outside   -->
           <!-- of Maven                                                               -->
           
           <envFactoryName>org.codehaus.mojo.natives.msvc.MSVC6EnvFactory</envFactoryName>
           
           <compilerStartOptions>
             <compilerStartOption> /MD /W4 -O</compilerStartOption>
             <compilerStartOption>-D_WIN32_WINNT=0x0500 </compilerStartOption>
           </compilerStartOptions>
          
           <!-- 
            | Add jdk include directories to system include path
            | Override ${jkdIncludePath} If your jdk does not conform to Sun JDK layout
            -->
           <javahOS>win32</javahOS>
            <sourceDirectory>src</sourceDirectory>
           <testSourceDirectory>test</testSourceDirectory>

           <!-- deploy the accompany .lib file as well -->          
           <linkerSecondaryOutputExtensions>lib</linkerSecondaryOutputExtensions >
          
           <linkerStartOptions>
             <linkerStartOption> /INCREMENTAL:NO /DLL user32.lib advapi32.lib oldnames.lib kernel32.lib </linkerStartOption>
           </linkerStartOptions>
         </configuration>
        
         <!-- Generate JNI header files based on a list of class name on the classpath -->
         <!-- The generated include directory is automatically added to include path at compile phase -->
         <!-- Ensure to have appropriate denpendency jar file(s) in your pom -->
         
         <executions>
           <execution>
             <id>javah</id>
             <phase>generate-sources</phase>
             <configuration>
               <classNames>
                 <className>class1</className>
                 <className>class2</className>
                 <className>...</className>
               </classNames>
               <!-- 
                |   Note: 
                |    1. Without classNames, javah mojo will search for all JNI classes 
                |       in your dependency list.
               -->
             </configuration>
             <goals>
               <goal>javah</goal> 
             </goals>
           </execution>
                    
         </executions>
        
    </build>
    
    
</project>