Maven Projects Setup

来源:互联网 发布:妇科专家在线网络咨询 编辑:程序博客网 时间:2024/06/08 15:51

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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 屋门对着厕所门怎么办 入室门对厨房门怎么办 厕所正对入户门怎么办 小区楼交错冲路怎么办 床的位置在五鬼上怎么办 被甩了很痛苦怎么办 和对象想分手了怎么办 对象想跟你啪啪怎么办 相亲对象好像不太想理我怎么办 想跟对象分手了怎么办 异地恋分手后该怎么办 面膜敷了一晚上怎么办 梦见被刺猬咬了怎么办 梦见死人叫我名字答应怎么办 香瓜苗叶子长斑怎么办 奶油打出来很稀怎么办 寄的水果压坏了怎么办 吃了一个烂水果怎么办 孕期吃了烂水果怎么办 邮快递水果坏了怎么办 快递寄水果坏了怎么办 闲鱼买家拒收水果怎么办 洗澡桶里有很多老鼠屎怎么办? 塑料和金属断了怎么办 孕妇吃了沙拉酱怎么办 孕妇淀粉吃多了怎么办 怀孕初期吃了杏怎么办 如果睡觉吃梨了怎么办 怀孕6个月有点贫血怎么办 怀孕八个多月有点贫血怎么办 生完小孩身体虚怎么办 孩子咳嗽厉害怎么办吃什么药 新生儿三天不拉大便怎么办 胃吃的变大了怎么办 小孩长高长的慢怎么办 小孩长高长得慢怎么办 小孩吃东西不吸收营养怎么办 婴儿长得太快怎么办 2个月婴儿长太快怎么办 孩子脚长得太快怎么办 4个月宝宝缺钙怎么办