Maven by Example - 5.3. Creating the Simple Web Project |
|
To create your web application: $ mvn archetype:generate -DgroupId=org.sonatype.mavenbook.simpleweb \ -DartifactId=simple-webapp \ -Dpackage=org.sonatype.mavenbook \ -Dversion=1.0-SNAPSHOT ... [INFO] [archetype:generate {execution: default-cli}] Choose archetype: ... 19: internal -> maven-archetype-webapp (A simple Java web application) ... Choose a number: (...) 15: : 19 Confirm properties configuration: groupId: org.sonatype.mavenbook.simpleweb artifactId: simple-webapp version: 1.0-SNAPSHOT package: org.sonatype.mavenbook.simpleweb Y: : Y [INFO] Parameter: groupId, Value: org.sonatype.mavenbook.simpleweb [INFO] Parameter: packageName, Value: org.sonatype.mavenbook.simpleweb [INFO] Parameter: package, Value: org.sonatype.mavenbook.simpleweb [INFO] Parameter: artifactId, Value: simple-webapp [INFO] Parameter: basedir, Value: /private/tmp [INFO] Parameter: version, Value: 1.0-SNAPSHOT ... [INFO] BUILD SUCCESSFUL Once the Maven Archetype plugin creates the project, change
directories into the Initial POM for the simple-webapp Project. <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>org.sonatype.mavenbook.simpleweb</groupId> <artifactId>simple-webapp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>simple-webapp Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>simple-webapp</finalName> </build> </project>
Next, you will need to configure the Maven Compiler plugin to target Java 5. To do this, add the plugins element to the initial POM as shown in POM for the simple-webapp Project with Compiler Configuration. POM for the simple-webapp Project with Compiler Configuration. <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>org.sonatype.mavenbook.simpleweb</groupId> <artifactId>simple-webapp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>simple-webapp Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>simple-webapp</finalName> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> </project>
Notice the |