maven打包 jar和war一起
时间: 2023-09-03 18:02:51 浏览: 191
Maven是一个强大的构建工具,可以帮助我们自动化地构建、管理和发布项目。要使用Maven打包jar和war一起,可以通过配置pom.xml文件来实现。
首先,你需要在pom.xml文件中添加以下插件配置:
```
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>jar-packaging</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.example.Main</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<executions>
<execution>
<id>war-packaging</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<warName>my-webapp</warName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
以上配置中,`maven-jar-plugin`用于打包成jar文件,并指定了主类。`maven-war-plugin`用于打包成war文件,并指定了war文件名。
接下来,使用命令`mvn package`执行构建命令。Maven将会按照配置打包成jar和war文件,并将它们一起存放在项目的`target`目录下。
这样,你就成功地使用Maven打包了jar和war一起。你可以将这些打包好的文件部署到相应的环境中运行。
阅读全文
相关推荐


















