Using Eclipse-maven-git to do Java Development (9)--eclipse New Maven Structure Project

Source: Internet
Author: User
Tags java se

The previous blog talked about how to use the Eclipse Maven Project New Wizard to create a new MAVEN project, but found that the new project was not available, explored, built a MAVEN-compliant project using Eclipse's General wizard, and converted to MAVEN engineering, This method is much more operable, so let me show you how to do it.

0. Preparation

In the old way, Eclipse works.

1. Target

Let's start with a directory structure that meets the requirements of the MAVEN project structure so that you know exactly what we're aiming for, first a javase:

Then there is the Java Web:

The red line crossed out is the "superfluous".

Knowing the target structure, let's step through the new projects, starting with the Java SE and then the Java Web.

2. Use the wizard to create a new MAVEN-compliant Java SE Project

First, Go to the wizard dialog box for new project:

Follow the instructions in the diagram, select Java Project, enter the wizard for the new Java SE Project, enter a name, and click Next.

In the entry page, is the key, you can see that the current "Source folder" and "Output folder" are not the same as expected,

So to speak, to change!

The modified method is very simple, first remove the SRC directory source code directory properties, and then add a new custom directory to the source directory list:

The source code directory we want to add is:


Add the directories in the order you are ready.

The effect after modification is as follows:

As you can see, the "Source folder" has met the target requirements, but "Output folder" is not satisfied, we need to compare the revision to


That is

Then just click on "Done" on the line.

Finally, the effect in Project view is:

3. Create a new Java Web project that conforms to the MAVEN structure using the wizard

Go to the wizard dialog box for the new project, enter the filter criteria "Web" in the dialog box selected by the project type, and select "Dynamic Web Project":

In the next step, enter the project name, which may be associated with Tomcat at "Target Runtime", but please select "None" and the other defaults, click "Next":

Similar to the new Java SE Project, the "Source Folder" needs to be modified, except that the dialog has changed, but nothing has changed.

Here the "Source folder" settings are the same, but "output folder" is a little different, the default is "Build\classes", that is, the path is based on the project, the path contains no project name, we need to modify it to:


You can not click "Done" here, and some settings need to be set, click to enter "Next",

The default "Content directory" is a directory called "WebContent", this is the root directory of Web resources, all Web resources are the starting directory is this directory, obviously this directory is not what we want, we need to modify to:


The option to generate the "Web. Xml" File is also checked, although it is now supported for configuration-free, but in fact, for projects like Spring, the Web. xml file is needed. Then click "Finish" to do it.

The effect of the project in the Project Exploer view is:

It is important to note that the Web root directory (which is circled there) is deep and difficult to actually operate, but it does not exist after the conversion to the MAVEN project.

4, the new project to the MAVEN project conversion

So far, the new two projects are still ordinary projects, and that Web Project Web resources editing is not particularly convenient, century clock will certainly not be finished, and then we need to convert it to a MAVEN project.

The conversion method is simple, eclipse is already built-in, the two-item conversion method is the same: Project Right- Configure, convert to Maven project,

Then there will be a pop-up box that asks to fill in the coordinates of the project, which can be defaulted, but it's best to fill in

To pay attention to the "package" selection, SE project selects the Jar,web project to select the war.

5. Analysis of results

For a Java SE project, there would be no noticeable visual change after converting to a MAVEN project, so no, but for the Java Web project, the observable change of the naked eye is a bit large:

The project's library is directly taken over by MAVEN (the Java SE Project is the same, but because it was only the JRE, so the change is not very large), the Web root directory also has a "Deployd resources" node, in fact, it is just a mapping, inside The WebApp is still the original WebApp, There is the Pom.xml file, this is the MAVEN project is the most critical files, converted to MAVEN project will automatically create this file, the information inside the project is the full configuration information (in fact, there are some default, and is not configured in this file).

View Pom.xml File:

Pom.xml for Java SE projects:

<project xmlns= ""  xmlns:xsi= " Xmlschema-instance "    xsi:schemalocation=" http:// ">    <modelversion>4.0.0</modelversion >    <groupId>cn.songxinqiang</groupId>    < Artifactid>tmjse</artifactid>    <version>0.0.1-snapshot</version>     <build>        <plugins>             <plugin>                 <artifactid>maven-compiler-plugin</ artifactid>                 <version>3.3</version> &Nbsp;              <configuration>                      <source />                     <target />                 </configuration>             </plugin>         </plugins>    </build></project>

Pom.xml for         java Web project:

<project xmlns= ""  xmlns:xsi= " Xmlschema-instance "    xsi:schemalocation=" http:// ">    <modelversion>4.0.0</modelversion >    <groupId>cn.songxinqiang</groupId>    < Artifactid>tmjee</artifactid>    <version>0.0.1-snapshot</version>     <packaging>war</packaging>    <build>         <plugins>             <plugin>                 <artifactId>maven-compiler-plugin</artifactId>                 <version>3.3</version>                 <configuration>                     <source>1.8</source>                      <target>1.8</target>                 </configuration>             </plugin>            < plugin>                < artifactid>maven-war-plugin</artifactid>                 <version>2.6</version>                 <configuration>                     <failonmissingwebxml>false</ failonmissingwebxml>                 </configuration>            < /plugin>        </plugins>    </build ></project>

Can be seen, the two are actually similar, just "packaging" is not the same, and then corresponding to the war package added a corresponding compilation plug-in, for these configuration instructions, you can view the official description of the Apache MAVEN project, this article does not say, there is time to say later.

6. Summary

This article describes how to create a new Java SE project and Java Web project that conforms to the MAVEN project structure through the Eclipse New Project Wizard, and convert it to a MAVEN project, which is better than the new project created with the Eclipse's own Maven Project New wizard. At least the structure is in line with the requirements, but this method is not the simplest and best method, and a future article will describe a "best" approach.

The next article will describe the transformation of Java SE and Java Web projects that do not conform to the MAVEN architecture to MAVEN engineering, and the structure of the analysis transformation.


Using Eclipse-maven-git to do Java Development (9)--eclipse New Maven Structure 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: 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.