简体   繁体   中英

How to include rmic package jar in maven assembly

I have a multi-module maven project that must have RMI stubs generated with it (to integrate with a legacy product that can't use dynamic proxies). I have configured the rmic-maven-plugin to do the rmic during the compile phase, and to package the stubs jar during the package phase.

<execution>
        <id>rmic-process-classes</id>
        <goals>
          <goal>rmic</goal>
        </goals>
        <phase>compile</phase>
        <configuration>
          <keep>true</keep>
          <!--outputDirectory>${project.build.outputDirectory}</outputDirectory-->
          <includes>
            <include>com.MyImpl</include>
          </includes>
        </configuration>
      </execution>
      <execution>
        <id>rmic-package</id>
        <goals>
          <goal>package</goal>
        </goals>
        <configuration>
          <!--outputDirectory>${project.build.outputDirectory}</outputDirectory>
          <finalName>broker-dl</finalName>
          <classifier>${project.version}</classifier-->
        </configuration>
      </execution>

I run into an issue after the assembly is created in my '-dist' module, which is a child module of the parent that exists to create the distribution archive. It does not include the client jar generated by the rmic-package execution.

How do I configured the assembly plugin to include the jar that the rmic plugin produces in the package phase? I tried adding a <files. section after the <moduleSets> , but when the files section is present, only those files end up in my assembly, as though the moduleSet section didn't exist.

      <moduleSets>
      <moduleSet>
          <useAllReactorProjects>true</useAllReactorProjects>
          <includes>
              <include>com:ImplModule</include>
           </includes>
          <binaries>
              <unpack>false</unpack>
              <fileMode>644</fileMode>
              <directoryMode>755</directoryMode>
              <dependencySets>
                <dependencySet>
                  <outputDirectory>lib</outputDirectory>
                </dependencySet>
              </dependencySets>
          </binaries>
      </moduleSet>     
   </moduleSets>
   <files>
       <file>           
           <outputDirectory>lib</outputDirectory>
           <source>../ImplModule/target/ImplModule-${project.version}-client.jar</source>
           <fileMode>644</fileMode>
       </file>       
   </files>

Note : I have read a related question but creating a Stub project seems impossible, since the RMI server class from which the stub is generated clearly needs to be a part of the main application jar, not part of a Stub jar, so I don't see how to rmic the RMI server in one module and yet javac it in another.

I was able to solve this problem myself by switching from using moduleSets to a combination of fileSets and a dependencySets. The fileSets pick up the main jar for the root of the assembly, and the rmic client jar from the rmic-package goal into the lib directory. Then, the dependencySet pulls all the dependencies of the main jar into the lib directory as well.

<!-- Include the -dl jar created by the rmic-package goal in
        the lib part of the assembly. It is necessary because 
        the target VM does not support dynamic RMI stubs, so the 
        stubs must be deployed in the assembly. -->
   <fileSets>
       <fileSet>
           <directory>../{project}/target</directory>
           <outputDirectory>.</outputDirectory>
           <!-- put the main jar in the top level -->
           <includes>
               <include>*.jar</include>
           </includes>
           <!-- don't include the RMIC-built -dl jar at the top -->
           <excludes>
               <exclude>*-dl-*.jar</exclude>
           </excludes>
       </fileSet>
       <fileSet>
           <directory>../{project}/target</directory>
           <outputDirectory>lib</outputDirectory>
           <!-- put the RMIC-built -dl jar in the lib dir -->
           <includes>
               <include>*-dl-*.jar</include>
           </includes>
       </fileSet>
   </fileSets>
   <dependencySets>
       <dependencySet>
           <!-- put all the dependencies in lib, as usual -->
           <useProjectArtifact>false</useProjectArtifact>
           <outputDirectory>lib</outputDirectory>             
           <excludes>
               <!-- don't include the main jar, which is at 
                    the top level already. -->
               <exclude>{groupId}:{artifact}</exclude>
           </excludes>
           <unpack>false</unpack>
       </dependencySet>
   </dependencySets>

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