zoukankan      html  css  js  c++  java
  • mvn cli 搭建项目架构

    创建如图所示目录结构

    在system-parent创建如下目录

    ├─system-dao

    ├─system-domain

    ├─system-service

    └─system-web

    创建system-parent

    mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-parent -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local

    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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.hbb0b0</groupId>
      <artifactId>system-parent</artifactId>
      <packaging>pom</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>system-parent</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
      <modules>
        <module>system-domain</module>
        <module>system-dao</module>
        <module>system-service</module>
        <module>system-web</module>
      </modules>
    </project>  
    

    说明

    • system-parent 只需要 pom文件
    • 修改 jarpom
    • 其中 节点的内容是子项目创建后自己加上去的,不用手工加

    创建子项目 system-domain

    mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-domain -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local

    pom.xml

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.hbb0b0</groupId>
        <artifactId>system-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <artifactId>system-domain</artifactId>
      <name>system-domain</name>
      <packaging>jar</packaging>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </project>
    

    说明

    • 去掉子项目 ,去掉之后表示子项目的version,groupid 继承自 system-parent pom
    • 添加 jar

    创建子项目 system-do

    mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-dao -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local

    pom.xml

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.hbb0b0</groupId>
        <artifactId>system-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <artifactId>system-dao</artifactId>
      <packaging>jar</packaging>
      <name>system-dao</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
    	<dependency>
          <groupId>com.hbb0b0</groupId>
          <artifactId>system-domain</artifactId>
          <version>${project.version}</version>
        </dependency>
      </dependencies>
    </project>
    

    说明

    • 去掉子项目 ,去掉之后表示子项目的version,groupid 继承自 system-parent pom
    • 添加 jar
    • system-dao 依赖 system-domain ,所以dependency 添加 system-domain 依赖

    创建子项目 system-service

    mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-service -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local

    pom.xml

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.hbb0b0</groupId>
        <artifactId>system-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <artifactId>system-service</artifactId>
      <name>system-service</name>
       <packaging>jar</packaging>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
    	<dependency>
          <groupId>com.hbb0b0</groupId>
          <artifactId>system-dao</artifactId>
          <version>${project.version}</version>
        </dependency>
    	
      </dependencies>
    </project>
    
    

    说明

    • 去掉子项目 ,去掉之后表示子项目的version,groupid 继承自 system-parent pom
    • 添加 jar
    • service 直接依赖 system-dao ,system-dao依赖system-domain,dependency 添加直接依赖 system-dao ,不需要添加system-domain 的依赖

    创建子项目 system-web

    mvn archetype:generate -DgroupId=com.hbb0b0 -DartifactId=system-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false -DarchetypeCatalog=local

    pom.xml

    
    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.hbb0b0</groupId>
        <artifactId>system-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <artifactId>system-web</artifactId>
      <packaging>war</packaging>
      <name>system-web Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
    	<dependency>
          <groupId>com.hbb0b0</groupId>
          <artifactId>system-service</artifactId>
          <version>${project.version}</version>
        </dependency>
      </dependencies>
      <build>
        <finalName>system-web</finalName>
    	<pluginManagement>
            <!--配置Jetty-->
            <plugins>
               <plugin>
                <groupId>org.mortbay.jetty</groupId>   
                 <artifactId>maven-jetty-plugin</artifactId>
                </plugin>
             </plugins>
         </pluginManagement>
      </build>
    </project>
    

    说明

    • 去掉子项目 ,去掉之后表示子项目的version,groupid 继承自 system-parent pom
    • 添加 jar
    • 添加 system-service 依赖
    • 添加 jetty 插件 ,这样做的目的,让web项目直接在命令行运行
      --修改 jsp文件 添加项目目录结构

    清理与编译

    在 system-parent目录运行

    mvn clean install

    执行成功之后 可以看到以下输出

    [INFO] system-parent ...................................... SUCCESS [ 0.562 s]

    [INFO] system-domain ...................................... SUCCESS [ 3.638 s]

    [INFO] system-dao ......................................... SUCCESS [ 0.956 s]

    [INFO] system-service ..................................... SUCCESS [ 0.956 s]

    [INFO] system-web Maven Webapp ............................ SUCCESS [ 0.795 s]

    [INFO] ------------------------------------------------------------------------

    [INFO] BUILD SUCCESS

    [INFO] ------------------------------------------------------------------------

    [INFO] Total time: 7.078 s

    [INFO] Finished at: 2018-04-23T22:42:37+08:00

    [INFO] Final Memory: 20M/192M

    [INFO] ------------------------------------------------------------------------

    运行web 项目

    mvn jetty:run

    运行成功之后控制台会输出一下信息

    [INFO] jetty-6.1.26

    [INFO] No Transaction manager fo

    [INFO] Started SelectChannelConn

    [INFO] Started Jetty Server

    maven web project

    浏览器结果

    http://localhost:8080/system-web/

    ---system-dao

    ---system-domain

    ---system-service

    ---system-web

  • 相关阅读:
    启动php-fpm时报错
    安装php时,make test报错
    安装php时,make步骤报错make: *** [sapi/fpm/php-fpm] Error 1
    安装php时,make步骤报错make: *** [ext/gd/gd.lo] Error 1
    运行phpize时出现:Cannot find autoconf. Please check your autoconf installation
    Linux下安装php加速组件XCache
    加速器eaccelerator不兼容高版本php
    Apache下Worker模式MPM参数分析
    Linux SVN直接删除版本库文件
    Linux SVN一次增加多个文件并批量上传
  • 原文地址:https://www.cnblogs.com/hbb0b0/p/8922429.html
Copyright © 2011-2022 走看看