首先在pom.xml文件中指定war的打包方式,war
<artifactId>test</artifactId><name>test</name><packaging>war</packaging>
上述代码在eclipse中执行maven install时, 会默认打成war,并放入本地仓库。
web项目时同时打包为war和jar文件
1、首先添加在pom.xml中添加插件 maven-jar-plugin , 使得 在调用命令mvn package install 或者 mvn package deploy 先生成 jar包。或者使用mvn package生成jar包。该插件生成的架包会放在工程的target文件夹下。
2、然后配置maven-install-plugin 插件, 使得在eclipse中执行maven install时, 同时生成jar和war到本地仓库。
3、再配置org.apache.maven.plugins插件, 使得在eclipse中执行deploy 时, 同时,生成jar和war到远程仓库。
源码如下:
<!-- package jar on package --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><executions><execution><phase>compile</phase><goals><goal>jar</goal></goals></execution></executions></plugin><!-- install jar to local repository --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-install-plugin</artifactId><executions><execution><phase>install</phase><goals><goal>install-file</goal></goals><configuration><packaging>jar</packaging><artifactId>${project.artifactId}</artifactId><groupId>${project.groupId}</groupId><version>${project.version}</version><file> ${project.build.directory}/${project.artifactId}-${project.version}.jar</file></configuration></execution></executions></plugin><!-- deploy jar to remote repository --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-deploy-plugin</artifactId><executions><execution><phase>deploy</phase><goals><goal>deploy-file</goal></goals><configuration><packaging>jar</packaging><generatePom>true</generatePom><url>${project.distributionManagement.repository.url}</url><artifactId>${project.artifactId}</artifactId><groupId>${project.groupId}</groupId><version>${project.version}</version><file>${project.build.directory}/${project.artifactId}.jar</file></configuration></execution></executions></plugin>
热门文章
- VPN天空 | 3月15日21M/S|免费Shadowrocket/Clash/V2ray/SSR订阅节点分享
- 宠物粮在哪里批发好(宠物粮在哪里批发好一点)
- 动物疫苗接种间隔时间是多久(动物疫苗一针多少钱)
- 宠物领养在哪里可以领钱(宠物领养渠道)
- 动物医院大众点评评语大全图片 动物医院大众点评100字通用评论
- python基础知识-pycharm版 第七天
- Oracle安装 – shmmax和shmall设置
- VPN天空 | 3月17日18.4M/S|免费Shadowrocket/SSR/V2ray/Clash订阅节点分享
- VPN天空 | 3月12日22.1M/S|免费SSR/Shadowrocket/Clash/V2ray订阅节点分享
- VPN天空 | 3月16日22.3M/S|免费Shadowrocket/SSR/V2ray/Clash订阅节点分享
归纳
-
64 2025-03