The core module of MyDistance
will contain a class that can be converted across different units, that is, from km/meter to yard/miles. Let's name this core module distance-core
. To create a core module, perform the following steps:
maven
via the search box, select Maven Module, and click on the Next button, as shown in the following screenshot:distance-core
, and browse to select the parent as Distance-main
, as shown in the following screenshot:
Field |
Value |
---|---|
Group Id |
|
Version |
|
Packaging |
|
Since the core module just contains a Java class and is available to be used as a library for a web module of an application, the packaging type is jar
.
distance-core
module gets created and the contents of the POM will look as follows:<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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.packt.mvneclipse</groupId> <artifactId>Distance-main</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>distance-core</artifactId> </project>
Please note that the parent of the module is enclosed in the <parent></parent>
tag. Also, the groupId
and version
tags will not be present for a module since we specified the same groupId
and version
as the parent in the Configure Maven Module wizard. We did this in the preceding code while creating a module.
At any point, if we wish to change or add groupId/version/artifactId
, we can always edit the pom.xml
file since it's an XML file.
com.packt.chpt6.mydistance.util
.ConversionUtil
in the preceding package. If you remember, we created this class in Chapter 5, Spicing Up a Maven Project. So, copy the contents of this class and save it.com.packt.chpt6.mydistance.util
, in src/test/java
. Add the class ConversionUtilTest
to the corresponding package. Refer to Chapter 5, Spicing Up a Maven Project, where we created this test class; copy the contents of this class and save it. The resulting src
structure will look as follows:You might notice that we have some errors, and the errors are due to the TestCase
class not being resolved. To solve this error, add jUnit
as a dependency to the parent module, the pom.xml
file, as shown in the following code:
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency>
3.129.42.243