• 【maven】之打包war依赖子项目jar


    比如

    p-common

    p-core

    p-dao

    p-service

    p-web

    service项目依赖dao,dao依赖core和common,web依赖service

    在使用maven tomcat7:run直接运行web的时候,我们发现maven默认只添加service,对于service依赖的dao以及传递依赖的dao,common,core都没有添加到项目中

    这就会产生ClassNotFound异常!

    解决这个问题有两种方法

    1、在web的pom中将依赖的jar重新引入一遍,如下

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>

    但是这种明显违背maven设计初衷,并且多出大量无用配置

    2、使用maven插件

    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
    </dependency>

    <plugin>  
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-assembly-plugin</artifactId>  
           <configuration>  
                 <descriptorRefs>  
                        <descriptorRef>jar-with-dependencies</descriptorRef>  
                 </descriptorRefs>  
            </configuration>  
     </plugin> 

    关于 maven-assembly-plugin 插件的说明

    http://maven.apache.org/components/plugins/maven-assembly-plugin/

    1、可以自定义打包配置文件

    2、可以将jar打包成独立运行jar

    ....

  • 相关阅读:
    flex自适应小例子
    hasOwnProperty 递归 简单回调 链式调用
    H5音频和视频
    html特殊字符
    css巧妙实现分隔线
    SQL Server中数据的存储
    SQL高级查询
    SQL SERVER查询到的数据转为Json格式
    SQL动态生成列
    SQL合并查询数据,以逗号分隔
  • 原文地址:https://www.cnblogs.com/gyjx2016/p/7145426.html
Copyright © 2020-2023  润新知