如何通过Maven仅部署ejb-client并解决父POM依赖缺失问题
解决Maven EJB客户端生成与依赖的两个问题
我来帮你逐个搞定这两个Maven配置问题,直接上可落地的方案:
问题1:仅安装/部署ejb-client jar,跳过完整EJB包
默认情况下,maven-ejb-plugin会同时生成主EJB包和client包,并都安装到仓库。要只保留client包的话,我们可以通过配置maven-install-plugin和maven-deploy-plugin来跳过主包的安装/部署,单独处理client包:
配置安装插件(仅安装ejb-client)
在你的EJB模块pom.xml中添加以下配置:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> <executions> <!-- 跳过主EJB包的安装 --> <execution> <id>default-install</id> <phase>install</phase> <goals> <goal>install</goal> </goals> <configuration> <skip>true</skip> </configuration> </execution> <!-- 安装ejb-client作为主构件 --> <execution> <id>install-ejb-client</id> <phase>install</phase> <goals> <goal>install-file</goal> </goals> <configuration> <file>${project.build.directory}/${project.build.finalName}-client.jar</file> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <packaging>ejb-client</packaging> </configuration> </execution> </executions> </plugin>
配置部署插件(仅部署ejb-client)
如果需要部署到远程仓库,再添加以下配置:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> <executions> <!-- 跳过主EJB包的部署 --> <execution> <id>default-deploy</id> <phase>deploy</phase> <goals> <goal>deploy</goal> </goals> <configuration> <skip>true</skip> </configuration> </execution> <!-- 部署ejb-client到远程仓库 --> <execution> <id>deploy-ejb-client</id> <phase>deploy</phase> <goals> <goal>deploy-file</goal> </goals> <configuration> <file>${project.build.directory}/${project.build.finalName}-client.jar</file> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <packaging>ejb-client</packaging> <url>${project.distributionManagement.repository.url}</url> <repositoryId>${project.distributionManagement.repository.id}</repositoryId> </configuration> </execution> </executions> </plugin>
这样执行mvn clean install或mvn clean deploy时,就只会处理ejb-client包了。
问题2:客户端解析时找不到未发布的父pom
这个问题很简单,只需要在你的EJB模块pom.xml的<parent>节点中添加<relativePath>,指定父pom的本地相对路径即可。Maven会优先从这个路径查找父pom,而不会去远程仓库搜索。
比如,如果父pom和你的EJB模块在同一项目根目录下(结构如下):
your-project/ ├── pom.xml <!-- 父pom --> └── artifact-ejb/ └── pom.xml <!-- EJB模块pom -->
那EJB模块的parent配置应该改成:
<parent> <groupId>your.parent.groupId</groupId> <artifactId>parent-artifact-id</artifactId> <version>parent-version</version> <relativePath>../pom.xml</relativePath> <!-- 指向父pom的相对路径 --> </parent>
根据你的实际项目结构调整<relativePath>的值即可,比如父pom在其他目录就写对应的相对路径,这样客户端依赖解析时就能找到父pom了,而且不需要发布父pom到仓库。
内容的提问来源于stack exchange,提问作者Fabrizio Stellato
相关产品推荐
相关产品推荐

