Using IntelliJ idea to build a multi-maven module Java project

Source: Internet
Author: User

I. New projects and modules

Steps:

1. Create a new project because the MAVEN management jar package is very convenient, so create a MAVEN project: New Project->maven-> (Create from archetype not checked)->next-fill in

GroupId:Com.multiplemoduleprojectdemo

Artifactid:Project

Version:1.0-snapshot

->project Name:multiplemoduleprojectdemo

2. Delete unnecessary folders (SRC, target)

3. In the project to create a new module, continue to select the Maven module, this time check create form archetype, select Maven-archetype-webapp,next-> fill Artifactid for the Web( Groupid/version and project consistency)->next-module Name:web

4. Continue creating a new Maven module without checking the Create form Archetype,artifactid:service Module Name:service

5. There are currently two projects under project

Second, the correlation module

How to associate a module? For example, the Web is the final module of the run, which is a Web project that needs to refer to the Service module's methods, classes, and so on.

Steps:

1. Open the module settings and right-click Web Project->open Module Settings

2. Configuring a Dependent service project

3. Note that the above dependencies only ensure that the project can be compiled correctly, that it cannot run successfully, and that it needs to configure MAVEN package dependencies

Third, new test class

1. Create a new class in the Java directory of the Service project and find no prompt, you need to first mark the Java folder as SourceRoot

2. New package Com.service, build class in Package Message.java

Package com.service;

public class Message {

public static string Show (String msg) {
String s = "Hello" +msg;
System.out.println (s);
return s;
}
}




3. Create a new JSP page in the Web module reference this kind of test

Find no Java folder, create new folder and mark as source Root

New Package Com.web, package-built class Callmessage.java

Package com.web;
Import Com.service.Message;
public class Callmessage {
Public String Show () {
Return Message.show ("world!");
}
}

4. Modify the Index.jsp page as follows:

<%@ page contenttype= "Text/html;charset=utf-8" language= "java"%>
<%@ page import= "Com.web.CallMessage"%>
<title>index</title>
<body>

<div>
<%=new callmessage (). Show ()%>
</div>

</body>

Iv. Adding a running environment

V. MAVEN Configuration JAR Package

In the Open folder: Shift-Right-click in the space, choose here to open the Command window, enter the command mvn clean install, return

Vi.. Operation

Using IntelliJ idea to build a multi-maven module Java project

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.