我有一个多模块maven项目,必须使用它生成RMI存根(以便与不能使用动态代理的传统产品集成)。我已经配置了rmic-maven-plugin来在编译阶段执行rmic,并在封装阶段打包存根jar。
<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>
在我的'-dist'模块中创建程序集后,我遇到了一个问题,该模块是用于创建分发存档的父模块的子模块。它不包括rmic-package执行生成的客户端jar。
如何配置程序集插件以包含rmic插件在程序包阶段生成的jar?我尝试在<files.
之后添加<moduleSets>
部分,但是当文件部分存在时,仅这些文件最终出现在我的程序集中,就好像moduleSet部分没有存在。
<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>
注意:我读过related question但是创建一个Stub项目似乎不可能,因为生成存根的RMI服务器类显然需要成为主应用程序的一部分jar,不是Stub jar的一部分,所以我不知道如何在一个模块中使用RMI服务器,而在另一个模块中使用javac。
答案 0 :(得分:0)
我能够通过使用moduleSets切换到fileSets和dependencySets的组合来解决这个问题。 fileSets选择程序集根目录的主jar,以及从rmic-package目标到lib目录的rmic客户端jar。然后,dependencySet也将主jar的所有依赖项拉入lib目录。
<!-- 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>