IntelliJ idea package into a war (including Maven project) Click the Open link
The first thing to do in the MAVEN project is the POM. Configure the desired configuration in XML:
1 <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0/http Maven.apache.org/xsd/maven-4.0.0.xsd "> 2 <modelversion>4.0.0</ modelversion> 3 <groupId>com.abc.java</groupId> 4 <artifactId>coressm</artifactId> 5 < version>0.0.1-snapshot</version> 6 <packaging>war</ Packaging>
1 <!--https:// mvnrepository.com/artifact/org.apache.maven.plugins/maven-war-plugin--> 2 <dependency>3 <groupid>org.apache.mav En.plugins</groupid>4 <ARTIFACTID>MAVEN-WAR-PLUGIN</ARTIFAC Tid>5 <version>3.0.0</version> 6 </dependency>
<!--Build #s--<build> <plugins> <plugin> <groupid>org.apache.maven.plugins</ Groupid> <artifactId>maven-war-plugin</artifactId> <configuration> <!-- to ignore the missing web. XML detection mechanism, the Dynamic Web Module 3.0 Engineering age does not require the XML file to register related content, so the project does not generate Web. XML by default. -<failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> < Plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>maven-compiler-plugin</ artifactid> <version>3.2</version> <executions> <execution> <id>default-compile </id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </ Execution> </executions> <configuration> <!--Use this configuration when using jdk1.7, if you want to use jdk1.8, the following 2 lines are modified to 1.8---< source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </ Configuration> </plugin> </plugins> </build> <!--build #e--</project>
MVN command to fight the war package (including the source jar package)
Pom.xml If no package type is specified, the default package type is jar
1, ensure that the pom.xml inside the introduction of:
1 <!--https://Mvnrepository.com/artifact/org.apache.maven.plugins/maven-war-plugin-- >2 <dependency>3 <groupid>org.apache.maven.plugins</groupid >4 <artifactId>maven-war-plugin</artifactId>5 <version>3.0.0 </version>6 </dependency>
2. Ensure that the project introduces the JDK, not the JRE;
3, to ensure that the project does not error, in turn, the implementation of MVN clean--> MVN package;
or Project right-click the run-->mvn clean-->mvn build...-->goals text box and enter "package";
4, if the project has an exclamation point, it is likely that the build path inside the Maven dependencies inside the missing jar, you can find the jar corresponding to the local repository path, After you delete the. lastupdated file that corresponds to the version number, delete the item, and then right-click-->maven-->update Project.
The first: package with the Pom.xml file.
Right-click the Pom.xml file and select Debug as or run as. But you need to choose Maven Install package
After successful execution, the log prints out the location (see if its configuration is log output). If there is no output, in the default C drive. M2 folder
The second way: Right-click the project. Select Debug as or Run as. But this time to choose Debug configurations
Browse Workspace Select the item that needs to be packaged, and then enter the clean install command in goals: After Debug executes, the war package is generated in the target directory
The Web project is packaged as a war and jar file at the same time
1. Add the plug-in Maven-jar-plugin in Pom.xml first, making the call command MVN the package install or MVN. Or use the MVN package to generate the jar packages. The package generated by the plugin is placed under the target folder of the project.
2. Then configure the Maven-install-plugin plug-in so that when you execute maven install in Eclipse, both the jar and the war are generated to the local repository.
3. Then configure the Org.apache.maven.plugins plug-in so that when you execute deploy in Eclipse, both the jar and the war are generated to the remote repository.
Pom. XML configuration:
1<!-- PackageJar on Package-2<plugin>3<groupId>org.apache.maven.plugins</groupId>4<artifactId>maven-jar-plugin</artifactId>5<executions>6<execution>7<phase>compile</phase>8<goals>9<goal>jar</goal>Ten</goals> One</execution> A</executions> -</plugin> -<!--install jar to local repository-- the<plugin> -<groupId>org.apache.maven.plugins</groupId> -<artifactId>maven-install-plugin</artifactId> -<executions> +<execution> -<phase>install</phase> +<goals> A<goal>install-file</goal> at</goals> -<configuration> -<packaging>jar</packaging> -<artifactId>${project.artifactId}</artifactId> -<groupId>${project.groupId}</groupId> -<version>${project.version}</version> in<file> -${project.build.directory}/${project.artifactid}-${project.version}.jar to</file> +</configuration> -</execution> the</executions> *</plugin> $<!--deploy jar to remote repository-Panax Notoginseng<plugin> -<groupId>org.apache.maven.plugins</groupId> the<artifactId>maven-deploy-plugin</artifactId> +<executions> A<execution> the<phase>deploy</phase> +<goals> -<goal>deploy-file</goal> $</goals> $<configuration> -<packaging>jar</packaging> -<generatePom>true</generatePom> the<url>${project.distributionManagement.repository.url}</url> -<artifactId>${project.artifactId}</artifactId>Wuyi<groupId>${project.groupId}</groupId> the<version>${project.version}</version> -<file>${project.build.directory}/${project.artifactId}.jar</file> Wu</configuration> -</execution> About</executions> $</plugin>
Exporting a war using Eclpise
1. Right-click on the item that needs to be packaged > select [Export]
2. Select [WAR file] under [Web] and click [Next]
3. Select Save path via [Browse] and click [Finish] to finish.
Exporting a war using Maven
1. Through Eclipse mode: Select the [Maven install] for the project you want to package right-click [Run as]. When prompted successfully, the path of the war package is displayed, typically under the target directory of the project.
2. Through the MAVEN command: the console enters the project directory and executes the MVN Package command. The path to the generated war package will be prompted after success. Typically in the target directory of the project.
Note: Pom.xml's <packaging/> configuration is a war package after the war is packaged, and the jar package is packaged when configured as a jar. Both the MVN Package command and the MVN install command can be packaged. My project name here is tsj-spring, so the default name is Tsj-spring.war.
This article refers to the article: http://blog.csdn.net/xlxxcc/article/details/52623855http://blog.csdn.net/big1989wmf/article/details/70144731
http://blog.csdn.net/u012586389/article/details/67635480
How to package Maven project-war packages in eclipse