maven学习笔记


1. maven项目目录结构

idea新建maven工程,结构如图:

maven官网给出的目录结构标准:

${basedir}
|-- pom.xml                   // Maven build项目的配置信息文件
|-- src             | |-- main | | `-- java        // 项目源代码目录 | | `-- resources // 项目资源文件目录 | | `-- filters // 项目资源过滤文件目录 | | `-- webapp // web应用源代码目录 | |-- test          // 测试目录 | | `-- java         | | `-- resources      | | `-- filters       | |-- it | |-- assembly        //打包描述文件目录
| |-- site           |-- LICENSE.txt |-- NOTICE.txt |-- README.txt

参考:maven官网标准目录结构介绍

2. pom.xml配置

参考:maven官网pom文件介绍

pom文件位于工程根路径下,包含了项目配置细节信息,maven基于这些信息构建项目。

以实际项目为例,项目目录为:

${basedir}
|-- pom.xml                   // 父pom文件
|-- gatekeeper-tool
|   |-- pom.xml            
|   |-- src
|   |   |-- main       
|   |   |-- test       
|   |   |-- assembly    
|-- gatekeeper-web
|   |-- pom.xml            
|   |-- src
|   |   |-- main       
|   |   |-- test       
|   |   |-- assembly    
|   |   |   `-- assembly.xml
|   |   |   `-- assembly-2.0.0.xsd 

父pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         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:artifactId:version-->
    <groupId>com.eageldiao</groupId>
    <artifactId>gatekeeper</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>
    <modules>
        <module>gatekeeper-web</module>
        <module>gatekeeper-tool</module>
    </modules>
</project>

子模块项目中的pom

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
  <!-- 父pom-->
<parent> <groupId>com.eaglediao</groupId> <artifactId>gatekeeper</artifactId> <version>0.0.1</version> </parent> <artifactId>gatekeeperweb</artifactId> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <spring.version>4.3.7.RELEASE</spring.version> <spring.security.version>4.2.2.RELEASE</spring.security.version> <maven.test.skip>false</maven.test.skip> <hibernate.version>5.4.1.Final</hibernate.version> <log4j.version>2.7</log4j.version> <jackson.version>2.8.6</jackson.version> </properties> <dependencies> <!--quartz--> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.3</version> </dependency>      ...略 </dependencies>

<build> <defaultGoal>install</defaultGoal> <finalName>${project.version}</finalName> <resources> <resource> <directory>src/main/webapp</directory> <targetPath>webapp</targetPath> </resource> <resource> <directory>src/main/resources</directory> </resource> <resource> <directory>src/main/conf</directory> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/assembly/assembly.xml</descriptor> </descriptors> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <configuration> <includes> <include>com/**</include> </includes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> </plugin> </plugins> </build> </project>

3.assembly.xml配置

参考: maven官网assembly配置介绍

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
    <id>release</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <includes>
                <include>*:*:*:*</include>
            </includes>
            <outputDirectory>lib</outputDirectory>
            <fileMode>0755</fileMode>
            <directoryMode>0755</directoryMode>
        </dependencySet>
    </dependencySets>
<fileSets> <fileSet> <directory>src/main/conf</directory> <outputDirectory>witeco-conf</outputDirectory> <fileMode>0755</fileMode> <directoryMode>0755</directoryMode> </fileSet> <fileSet> <directory>src/main/resources</directory> <outputDirectory>witeco-conf</outputDirectory> <fileMode>0755</fileMode> <directoryMode>0755</directoryMode> <lineEnding>unix</lineEnding> </fileSet> <fileSet> <directory>src/main/webapp</directory> <outputDirectory>webapp</outputDirectory> <fileMode>0755</fileMode> <directoryMode>0755</directoryMode> </fileSet> <!-- bin目录下启动脚本 --> <fileSet> <directory>src/main/script/startup</directory> <outputDirectory>bin</outputDirectory> <fileMode>0755</fileMode> <directoryMode>0755</directoryMode> <lineEnding>unix</lineEnding> </fileSet> <!-- tool目录下工具脚本 --> <fileSet> <directory>src/main/script/tool</directory> <outputDirectory>tool</outputDirectory> <fileMode>0755</fileMode> <directoryMode>0755</directoryMode> <lineEnding>unix</lineEnding> </fileSet> <!-- tool目录下jre --> <fileSet> <directory>src/main/tool/jre</directory> <outputDirectory>tool/jreTmp</outputDirectory> <fileMode>0755</fileMode> <directoryMode>0755</directoryMode> </fileSet> </fileSets> </assembly>

优质内容筛选与推荐>>
1、上下界网络流总结
2、直接插入排序
3、python3 重写、重用、重载
4、Object类型
5、joomla安装


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn