plh97 / blog

✏️blog. writing in issues.
https://plhh.xyz/
82 stars 8 forks source link

Java - Maven #118

Closed plh97 closed 5 years ago

plh97 commented 6 years ago

Maven简介

Maven是一个项目包管理器,为开发人员构建完整的构建生命周期框架.由于Maven使用标准的目录布局和构建生命周期,开发人员基本可以用它构建自动化立即构建的项目基础架构.

由于多个开发团队的环境的不同,Maven可以立即构建标准设置工作方式.简单来说,就是标准化了,以及简化了开发人员初始项目构建.

Maven为开发人员如下方法的方法:

总结

Maven标准化,简化了项目开发流程.它同时无缝处理了汇编分发,文档,团队协作和其他任务.Maven增加了复用,并且管理了照顾了大多数构建相关任务.

Maven历史

Maven是被用来简化项目构建流程的.它是Apache团队开源的项目,被用来构建项目.

Maven 项目构建目的

Maven项目结构和内容在pom.xml文件中,代码如下

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>java-demo</groupId>
    <artifactId>com.pipk</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <!-- TODO project name  -->
    <name>quickstart</name>
    <description></description>
    <!-- TODO
        <organization>
        <name>company name</name>
        <url>company url</url>
        </organization>
    -->
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <dependencies>
        <!--  WICKET DEPENDENCIES -->
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket</artifactId>
            <version>${wicket.version}</version>
        </dependency>
        <!-- OPTIONAL 
            <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-extensions</artifactId>
            <version>${wicket.version}</version>
            </dependency>
        -->
        <!-- LOGGING DEPENDENCIES - LOG4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.4.2</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>
        <!--  JUNIT DEPENDENCY FOR TESTING -->
         <dependency>
                 <groupId>junit</groupId>
                 <artifactId>junit</artifactId>
                 <version>3.8.2</version>
                 <scope>test</scope>
         </dependency>
        <!--  JETTY DEPENDENCIES FOR TESTING  -->
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty</artifactId>
            <version>${jetty.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>${jetty.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-management</artifactId>
            <version>${jetty.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/java</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <filtering>false</filtering>
                <directory>src/test/java</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <properties>
        <wicket.version>1.3.2</wicket.version>
        <jetty.version>6.1.4</jetty.version>
    </properties>
</project>

Maven便捷配置

开发人员不必配置所有的配置,Maven帮你配置好了,并且提供了默认配置.就在pom.xml文件中,

.
├── compipk.iml
├── pom.xml
├── src
│   ├── main
│   │   ├── java          =====>>>>>        源码
│   │   │   └── java-demo
│   │   │       ├── HomePage.html
│   │   │       ├── HomePage.java
│   │   │       └── WicketApplication.java
│   │   ├── resources          =====>>>>>        资源
│   │   │   └── log4j.properties
│   │   └── webapp
│   │       └── WEB-INF
│   │           └── web.xml
│   └── test          =====>>>>>        测试
│       └── java
│           └── java-demo
│               ├── Start.java
│               └── TestHomePage.java
└── target          =====>>>>>        前台页面静态资源放置处
    ├── classes
    │   ├── java-demo
    │   │   └── HomePage.html
    │   └── log4j.properties
    └── generated-sources          =====>>>>>        java编译好的代码
        └── annotations

为了构建项目,Maven为开发人员提供了生命周期和项目依赖的配置,开发人员可以在不知道插件工作情况的情况下引入,