Home
Cloud
Big Data
CI
Install
Samples
Java
Ubuntu
Maven
Archive
Maven
|
Create a web module (war file)
Using the archetype "maven-archetype-webapp"
POM file (sample)
Using the archetype "maven-archetype-webapp"
$ mvn archetype:generate \ -DarchetypeGroupId=org.apache.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-webapp \ -DarchetypeVersion=1.4 \ -DgroupId=mtitek.maven.war.samples \ -DartifactId=mtitek-maven-war-samples \ -Dversion=1.0.0-SNAPSHOT \ -DinteractiveMode=false
$ find ./mtitek-maven-war-samples/ -type f ./mtitek-maven-war-samples/pom.xml ./mtitek-maven-war-samples/src/main/webapp/index.jsp ./mtitek-maven-war-samples/src/main/webapp/WEB-INF/web.xml
POM file (sample)
Once the project generated, you can adjust the POM file.
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>mtitek.maven.war.samples</groupId> <artifactId>mtitek-maven-war-samples</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>19</maven.compiler.source> <!-- maven-compiler-plugin property --> <maven.compiler.target>19</maven.compiler.target> <!-- maven-compiler-plugin property --> </properties> <dependencies> <dependency> <groupId>mtitek.maven.jar.samples</groupId> <artifactId>mtitek-maven-jar-samples</artifactId> <version>1.0.0-SNAPSHOT</version> <type>jar</type> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.3.2</version> <configuration> <packagingIncludes> **/*.htm, **/*.css, **/*.js, **/*.jsp, **/*.class, WEB-INF/lib/mtitek-*.jar </packagingIncludes> <archive> <manifest> <addClasspath>true</addClasspath> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> <manifestEntries> <Implementation-Build>${project.version}</Implementation-Build> </manifestEntries> </archive> </configuration> <executions> <execution> <id>default-war</id> <phase>package</phase> <goals> <goal>war</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>11.0.13</version> </plugin> </plugins> </build> </project>
Build the project:
$ mvn clean install
Use the the goal "jetty:run" to run the web application:
$ mvn jetty:run
[INFO] Configuring Jetty for project: mtitek-maven-war-samples [INFO] Context path = / [INFO] Started Jetty Server
Use "curl" to test the web application:
$ curl http://localhost:8080/
<html> <body> <h2>Hello World!</h2> </body> </html>
© 2010-2022
mti
tek