Maven by Example - 4.3. Creating the Simple Weather Project |
|
First, let’s use the Maven Archetype plugin to create a basic skeleton
for the Simple Weather project. Execute the following command to
create a new project, press enter to use the default
$ mvn archetype:generate -DgroupId=org.sonatype.mavenbook.custom \ -DartifactId=simple-weather \ -Dversion=1.0 [INFO] Preparing archetype:generate ... [INFO] [archetype:generate {execution: default-cli}] [INFO] Generating project in Interactive mode [INFO] No archetype defined. Using maven-archetype-quickstart \ (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: ... 16: internal -> maven-archetype-quickstart () ... Choose a number: (...) 16: : 16 Confirm properties configuration: groupId: org.sonatype.mavenbook.custom artifactId: simple-weather version: 1.0 package: org.sonatype.mavenbook.custom Y: : Y [INFO] Parameter: groupId, Value: org.sonatype.mavenbook.custom [INFO] Parameter: packageName, Value: org.sonatype.mavenbook.custom [INFO] Parameter: package, Value: org.sonatype.mavenbook.custom [INFO] Parameter: artifactId, Value: simple-weather [INFO] Parameter: basedir, Value: /private/tmp [INFO] Parameter: version, Value: 1.0 [INFO] BUILD SUCCESSFUL Once the Maven Archetype plugin creates the project, go into the
Initial POM for the simple-weather 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.custom</groupId> <artifactId>simple-weather</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>simple-weather</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> </project>
Next, you will need to configure the Maven Compiler plugin to target
Java 5. To do this, add the POM for the simple-weather 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.custom</groupId> <artifactId>simple-weather</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>simple-weather</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> <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 that we passed in the |