zoukankan      html  css  js  c++  java
  • Maven多模块项目 eclipse热部署 Maven项目实现 tomcat热部署

    Maven 多模块项目在eclipse下面热部署,即你可以体验下无论你修改整个项目里面的任何模块的代码,都不需要用maven打包就可以看到效果,

    1、首先准备好创建一个maven多项目的代码,准备好一个eclipse,一个tomcat,什么java环境,tomcat环境我就不多说了,如果这个你都没有配好就别往下看了,

    2、创建项目,mvn archetype:generate -DgroupId=com.laoshuisheng -DartifactId=test -Dversion=1.0

    创建成功后到pom.xml文件里面修改pom.xml

     

    [xhtml] view plaincopy
    1. project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    2.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
    3.   <modelVersion>4.0.0</modelVersion>  
    4.   
    5.   <groupId>com.laoshuisheng</groupId>  
    6.   <artifactId>test</artifactId>  
    7.   <version>1.0</version>  
    8.   <packaging>jar</packaging>  
    9.   
    10.   <name>test</name>  
    11.   <url>http://maven.apache.org</url>  
    12.   
    13.   <properties>  
    14.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    15.   </properties>  
    16.   
    17.   <dependencies>  
    18.     <dependency>  
    19.       <groupId>junit</groupId>  
    20.       <artifactId>junit</artifactId>  
    21.       <version>3.8.1</version>  
    22.       <scope>test</scope>  
    23.     </dependency>  
    24.   </dependencies>  
    25. </project>  

     

    修改成下面

     

    [xhtml] view plaincopy
    1. oject xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    2.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
    3.   <modelVersion>4.0.0</modelVersion>  
    4.   
    5.   <groupId>com.laoshuisheng</groupId>  
    6.   <artifactId>test</artifactId>  
    7.   <version>1.0</version>  
    8.   <packaging>pom</packaging>  
    9.   
    10.   <name>test</name>  
    11.   <url>http://maven.apache.org</url>  
    12.   
    13.   <properties>  
    14.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    15.   </properties>  
    16.   
    17.   <dependencies>  
    18.     <dependency>  
    19.       <groupId>junit</groupId>  
    20.       <artifactId>junit</artifactId>  
    21.       <version>3.8.1</version>  
    22.       <scope>test</scope>  
    23.     </dependency>  
    24.   </dependencies>  
    25. </project>  

     

    进入该项目里面随便的创建几个模块,我这里为了方便就只创建两个模块好了,一个就是web项目,一个就是业务代码

     

    .../test>mvn archetype:generate -DgroupId=com.laoshuisheng.web -DartifactId=test-web -DarchetypeArti
    factId=maven-archetype-webapp -Dversion=1.0

     

    创建业务代码项目:

     

    ../test>mvn archetype:generate -DgroupId=com.laoshuisheng.web -DartifactId=test-core -DarchetypeArt
    ifactId=maven-archetype-quickstart -Dversion=1.0

     

    创建完了如下图:

     

     

     

    好了现在项目创建成功了,我们要导入eclipse了,这一步也很重要,大家要细心的看了,导入的命令是:

     

    ...test>mvn eclipse:eclipse -Dwtpversion=1.0

     

    记得不要缺少 -Dwtpversion=1.0,这个说明了eclipse认出它就是web项目,而不是简单的java项目,大家应该知道web项目在eclipse可以做一些其他的事情吧。

     

     

     

     

    记住了,是一般的导入,不是maven项目导入。

     

     

     

    看见了吧,项目上面有个小地球,证明eclipse认出了他就是java web项目,没错,就是这个会给我们意想不到的效果

    接下来我们去把项目依赖加上,在web项目想的pom.xml里面增加对test-core的依赖:

     

     

    [xhtml] view plaincopy
    1. <?xml version="1.0"?>  
    2. <project  
    3.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"  
    4.     xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
    5.     <modelVersion>4.0.0</modelVersion>  
    6.     <parent>  
    7.         <artifactId>test</artifactId>  
    8.         <groupId>com.laoshuisheng</groupId>  
    9.         <version>1.0</version>  
    10.     </parent>  
    11.     <groupId>com.laoshuisheng.web</groupId>  
    12.     <artifactId>test-web</artifactId>  
    13.     <version>1.0</version>  
    14.     <packaging>war</packaging>  
    15.     <name>test-web Maven Webapp</name>  
    16.     <url>http://maven.apache.org</url>  
    17.     <dependencies>  
    18.         <dependency>  
    19.             <groupId>junit</groupId>  
    20.             <artifactId>junit</artifactId>  
    21.             <version>3.8.1</version>  
    22.             <scope>test</scope>  
    23.         </dependency>  
    24.         <dependency>  
    25.             <groupId>com.laoshuisheng.web</groupId>  
    26.             <artifactId>test-core</artifactId>  
    27.             <version>1.0</version>  
    28.         </dependency>  
    29.     </dependencies>  
    30.     <build>  
    31.         <finalName>test-web</finalName>  
    32.     </build>  
    33. </project>  

     

    加上后重新 mvn eclipse:clean eclipse:eclipse下刷新下eclipse的项目发现:

     

     

     

     

    这个时候就该配置到服务器上了,因为虽然说是maven项目,但是我们开发的时候服务器运行的是web下面的classes下的class文件和

    webapp下面的jsp/css/js等文件,所以并不需要打包什么的,如果是依赖如test-core也是跑classes的编译后的代码,所以也不需要编译,但是这里有个问题就是配置文件必须是放在classpath下面,因为我刚刚已经说了原因了,,废话不多说,看是配服务器,

     

     

     

     

     

     

     这就是我们创建好的tomcat服务器,然后大家点下   右键 ,记得是在服务器上点右键哦, 弹出个对话框,不错是弹出对话框,上面有个add and remove 的选项,你会发现有个test-web

     

     

     

     

    看到了吧,知道为啥我一定要强调导入项目的时候加上 -Dwtpversion=1.0了吧,这样他才能在这里加,eclipse才认出它就是web项目,哈哈,到这里基本上已经成功了,看看加后的效果:

     

     

     

     

    不错~不错,看到这样说明连带依赖的模块也成功加载了,嗯,现在你可以随意的修改这两块里面的代码,都不需要重新打包、不需要重新启动服务器,因为我们是运用了eclipse的热编译来实现的,或者说我们根本不需要在开发中运用到maven的功能。

     

     

    好了。到这里maven的多模块的项目的热编译就完全可以无任何插件的实现了,如果大家有什么不明白的直接来问我,谢谢!

  • 相关阅读:
    js 数据格式化
    js 获取URL中参数
    微信公众平台JSSDK开发
    js 日期格式化及日期增减
    一句话的设计模式
    微信小程序开源项目库汇总
    bash 配置文件
    centos 设置时间为北京时间
    数据库一般数据的查询操作
    linux tmux 工具使用 tmux.conf 文件
  • 原文地址:https://www.cnblogs.com/daichangya/p/12958921.html
Copyright © 2011-2022 走看看