Add MAVEN support for an existing Web project

Source: Internet
Author: User

To use MAVEN to build a project, need some upfront preparation, such as installing MAVEN, some knowledge about MAVEN, these can be directly on the internet Baidu, how to install the configuration maven can Baidu, and the JDK configuration is similar, Here's just how to add MAVEN support to an existing Web project.
My environment is: myeclipse10+tomcat6.0.26+jdk1.7
1, first according to Maven's statute to establish the source package: Src/main/java, Src/main/resources, Src/test/java, src/test/resources. To create a step:

Then enter the name and click Finish:

After creation, the directory structure is as follows:

2, in the root directory of the project to add the Pom file, the content of the Pom file can only write some of the necessary things:

3. Modify the. project file to make the current project a MAVEN project:
Under the "Buildspec" tab, add:

        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
Under the "Natures" tab, add:
<nature>org.eclipse.m2e.core.maven2Nature</nature>

After the above two revisions, you should see an "M" identifier in the project name:

Description MyEclipse has identified the project as a MAVEN project.

4, under the project's build path to remove the reference to the jar package in the Lib directory, now do not delete the jar package in the Lib directory, because the subsequent addition of dependencies in the Pom file may need to refer to these jar GroupID, Artifactid and version information.

5. Modify the. classpath file to enable the project to reference the jar package through dependencies in the Pom file. In the file, add:

<classpathentry kind= "Con" path= "Org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" >
        <attributes>
            <attribute name= "org.eclipse.jst.component.dependency" value= "/web-inf/lib"/>
        </attributes>
</classpathentry>
<classpathentry kind= "con" path= "Org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER "/>

The final. classpath file reads as follows:

The libraries of build path is as follows:

After this step, the project depends on the JARJ will be introduced through the Pom file, currently in the Pom file has not been added dependency, so the project should be error, the next step, as long as the project needs to add the jar in the pom file corresponding dependencies can be, do not know how to add the dependence of Baidu. Find dependencies for jars, here is a URL: http://search.maven.org/#search%7cga%7c1%7cpoi

problems encountered:
1. Project and. classpath files can be displayed in the following ways:

In the pop-up box, remove the. *resource Front tick:

2, after completing the above steps, all the code also compiled through, but found that in the test run a main function is always prompted to not load the main class:

later by the Pom file to specify the project's class in the directory to be able to add the following figure in the Red box content:

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.