Maven Projects Setup

1 篇文章 0 订阅

You can create project by maven. But basically, we don’t prefer to do it. We always use Eclipse/IntelliJ to create maven project.

After creating project by maven project template in IntelliJ, we got below folder.
MyWebApp
|–.idea
|–src
|—-main
|—-resources
|–test
|–pom.xml

By default, we only have one setting named as “POM.xml”. It includes all core information related to project building/dependencies/basic artefact information.

Initialize pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>myApp</groupId>
    <artifactId>myApp</artifactId>
    <version>1.0-SNAPSHOT</version>
</project>

Based on these initial settings, you can install package through maven clean install command.

Maven Build Process:

–validate: validate the project is correct and all necessary information is available
–compile: compile the source code of the project
–test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
–package: take the compiled code and package it in its distributable format, such as a JAR.
–integration-test: process and deploy the package if necessary into an environment where integration tests can be run
–verify: run any checks to verify the package is valid and meets quality criteria
–install: install the package into the local repository, for use as a dependency in other projects locally
–deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

However, we want to add some dependencies and repositories. Given that, we need to modify pom.xml & add another setting file named as “Settings.xml”.

There are two settings.
POM.xml:
(1) We want to add JUNIT dependency. Given that, we add below settings.

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
</dependencies>

(2) We want to add one plug-in when building projects, so that we add these settings.

<build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.11.v20150529</version>
                <configuration>
                    <webApp>
                        <contextPath>/MyWebApp</contextPath>
                    </webApp>
                    <httpConnector>
                        <port>80</port>
                    </httpConnector>
                </configuration>
            </plugin>
        </plugins>

    </build>

Settings.xml: This configuration manage the global level configuration information for all maven projects.

These include values such as the local repository location, alternate remote repository servers, and authentication information

We define local repository & remote repository.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <localRepository>/Users/kangxiwei/maven</localRepository>

    <interactiveMode>true</interactiveMode>

    <usePluginRegistry>false</usePluginRegistry>

    <profiles>
        <profile>
            <id>profile-default</id>
            <repositories>
                <repository>
                    <id>repo-mirror</id>
                    <url>http://maven.net.cn/content/groups/public/</url>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>plugin-repo-mirror</id>
                    <url>http://maven.net.cn/content/groups/public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>

    </profiles>
</settings>

Related links:
Maven in 5 Minutes
Maven Getting Started
Maven Settings.xml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值