Maven (4)-use intellij idea to create a maven multi-module project, intellijmaven
This article uses an example to describe how to use maven to build a multi-module jave project. Development Tool: intellij idea.
I. project structure
Multi-module-project is the main project, which contains two modules ):
2. Build Project 2.1 Parent Project
Create a blank standard maven project (do not select the Create from archetype option)
Enter project coordinates
Get a standard maven project. Because the project exists as a Parent project, you can directly Delete the src folder.
2.2 Add the web-app Module)
Select create from archetype (select webapp)
GroupId and version inherit from the Parent project. You only need to enter artifactId here.
2.3 Add the web-service Module
Use the same method to create the web-service module (however, this module is a blank maven standard project and should not be created from archetype)
2.4 final project structure
2.5 Key Points 3. Add project Dependencies
The preceding operation adds the web-app dependency on the web-service module. After completing the preceding operation, the public class in web-Service is visible in the web-app module. However, at this time, the app module uses classes in the service module. When compiling (compile) through maven, the system still reports the error XX cannot be found (XX is the class of the service module ), to solve this problem, you need to add service dependencies in the app pom:
<dependency> <groupId>com.cnblogs.kmpp</groupId> <artifactId>web-service</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
The project dependency has been added.
4. Start programming. 4.1 web-service module programming.
Add a service class (SimpleService. java) to the web-Service module)
4.2 web-app module programming
Add a Servlet to the web-app module and call the getServiceDescription method of the SimpleService class of the web-service module.
4.3 configure Servlet
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>Simple</servlet-name> <servlet-class>com.cnblogs.kmpp.SimpleServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Simple</servlet-name> <url-pattern>/simple-servlet</url-pattern> </servlet-mapping></web-app>
V. Running
Add the j2ee dependency and jetty plug-in dependency to the web-app pom. Run jetty. Details
Enter http: // localhost: 8080/web-app/simple-servlet in the browser
Get the running result:
Vi. End
This article demonstrates how to use maven to build a multi-module project.