• Maven 命令操作项目


    1.创建一个多模块的Java项目

    shift+鼠标右键

    创建项目命令:

    旧版:

    mvn archetype:create -DgroupId=com.qhong -DartifactId=MavenParent -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

    新版:

    mvn archetype:generate -DgroupId=com.qhong -DartifactId=MavenParent -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

    发现就改变一个单词,新版创建的速度真是太慢了

    用旧版方式创建报错:

    网上进行查找,发现在maven3.0.5以上版本舍弃了create,使用generate生成项目,我的是3.3.9版本,所以。。。

    新版创建成功

    创建的MavenParent项目中的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>com.qhong</groupId>
      <artifactId>MavenParent</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>MavenParent</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>
    </project>

    现在修改打包方式为pom

      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.qhong</groupId>
      <artifactId>MavenParent</artifactId>
      <packaging>pom</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>MavenParent</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>
    </project>
    View Code

    现在在MavenParent文件夹内部再次创建项目Service,不得不说,真慢!

    mvn archetype:generate -DgroupId=com.qhong -DartifactId=Service -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

    在创建一个Web,

    mvn archetype:generate -DgroupId=com.qhong -DartifactId=Web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false  

    查看MavenParent的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.qhong</groupId>
      <artifactId>MavenParent</artifactId>
      <packaging>pom</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>MavenParent</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>Service</module>
        <module>Web</module>
      </modules>
    </project>

    发现多了modules

    现在一个多模块项目就创建好了,MavenParent中的src文件没有用,可以删除了。

    用idea打开,查看整个结构:

    Service项目的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.qhong</groupId>
        <artifactId>MavenParent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <groupId>com.qhong</groupId>
      <artifactId>Service</artifactId>
      <version>1.0-SNAPSHOT</version>
      <name>Service</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>
    </project>
    View Code

    修改Web的pom.xml,使其依赖Service项目

    <?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.qhong</groupId>
        <artifactId>MavenParent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <groupId>com.qhong</groupId>
      <artifactId>Web</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>war</packaging>
      <name>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.qhong</groupId>
          <artifactId>Service</artifactId>
          <version>1.0-SNAPSHOT</version>
        </dependency>
      </dependencies>
      <build>
        <finalName>Web</finalName>
      </build>
    </project>
    View Code

    对Service进行安装

     

     下面对web项目进行打包,部署

    把打包好的Web.war包放在tomcat9的webapp下

    发现Web.war放下后会自动解压

    访问url

    http://www.cnblogs.com/tonychai/p/4538683.html

    http://www.cnblogs.com/xdp-gacl/p/4240930.html

  • 相关阅读:
    jquery拖拽插件 tableDnD
    爱回收jd图标
    struts2框架学习笔记2:配置详解
    struts2框架学习笔记1:搭建测试
    hibernate框架学习笔记12:查询优化
    hibernate框架学习笔记11:Criteria查询详解
    hibernate框架学习笔记10:HQL查询详解
    hibernate框架学习笔记9:多对多关系案例
    hibernate框架学习笔记8:一对多关系案例
    hibernate框架学习笔记7:HQL查询、Criteria查询简介
  • 原文地址:https://www.cnblogs.com/hongdada/p/5916339.html
Copyright © 2020-2023  润新知