使用Maven构建Dubbo服务的可运行jar包
本文为《基于Dubbo的分布式系统架构视频教程》的课程系列文档,更多课程信息,请关注:http://www.roncoo.com
Dubbo视频教程--基础篇--第07节--使用Maven构建Dubbo服务的可运行jar包
一、Dubbo服务的运行方式:
1、使用Servlet容器运行(Tomcat、Jetty等)----不可取
缺点:增加复杂性(端口、管理)
浪费资源(内存)
2、自建Main方法类来运行(Spring容器) ----不建议(本地调试可用)
缺点: Dobbo本身提供的高级特性没用上
自已编写启动类可能会有缺陷
3、使用Dubbo框架提供的Main方法类来运行(Spring容器)----建议使用
优点:框架本身提供(com.alibaba.dubbo.container.Main)
可实现优雅关机(ShutdownHook)
二、打包用的Maven 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>
<parent>
<groupId>wusc.edu.common</groupId>
<artifactId>edu-common-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../edu-common-parent</relativePath>
</parent>
<groupId>wusc.edu.service</groupId>
<artifactId>edu-service-user</artifactId>
<version>${edu-service-user.version}</version>
<packaging>jar</packaging>
<name>edu-service-user</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<log4j.leve>debug</log4j.leve>
<log4j.ale>debug</log4j.ale>
</properties>
<build>
<finalName>edu-service-user</finalName>
<resources>
<resource>
<targetPath>${project.build.directory}/classes</targetPath>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<!-- 结合com.alibaba.dubbo.container.Main -->
<resource>
<targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
<directory>src/main/resources/spring</directory>
<filtering>true</filtering>
<includes>
<include>spring-context.xml</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<!-- 解决Maven插件在Eclipse内执行了一系列的生命周期引起冲突 -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>target/classes/</classesDirectory>
<archive>
<manifest>
<mainClass>com.alibaba.dubbo.container.Main</mainClass>
<!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
<useUniqueVersions>false</useUniqueVersions>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<type>jar</type>
<includeTypes>jar</includeTypes>
<useUniqueVersions>false</useUniqueVersions>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>wusc.edu.common</groupId>
<artifactId>edu-common</artifactId>
<version>${edu-common.version}</version>
</dependency>
<dependency>
<groupId>wusc.edu.common</groupId>
<artifactId>edu-common-config</artifactId>
<version>${edu-common-config.version}</version>
</dependency>
<dependency>
<groupId>wusc.edu.common</groupId>
<artifactId>edu-common-core</artifactId>
<version>${edu-common-core.version}</version>
</dependency>
<dependency>
<groupId>wusc.edu.facade</groupId>
<artifactId>edu-facade-user</artifactId>
<version>${edu-facade-user.version}</version>
</dependency>
<!-- Common Dependency Begin -->
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<classifier>jdk15</classifier>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
</dependency>
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<!-- Common Dependency End -->
<!-- Spring Dependency Begin -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-struts</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
</dependency>
<!-- Spring Dependency End -->
<!-- MyBatis Dependency Begin -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<!-- MyBatis Dependency End -->
<!-- Struts2 Dependency Begin -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts.xwork</groupId>
<artifactId>xwork-core</artifactId>
</dependency>
<!-- Struts2 Dependency End -->
<!-- Others Begin -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>
<!-- Others End -->
<!-- Mysql Driver Begin -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Mysql Driver End -->
<!-- dubbo 需要的jar start -->
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
</dependency>
<!-- dubbo 需要的jar end -->
</dependencies>
</project>
具体打包过程请看视频内容,更多课程信息请关注Dubbo视频教程官网:http://www.roncoo.com
转载于:https://blog.51cto.com/wushuicheng/1704382
使用Maven构建Dubbo服务的可运行jar包相关推荐
- 使用maven构建dubbo服务的可执行jar包
maven 项目结构 <build><!-- 使用dubbo推荐的方法,打包成jar,调用main方法启动 --><finalName>admin-service- ...
- java如何转成jar包,修改及反编译可运行Jar包实现过程详解
将可运行Jar包,反编译成项目,修改代码,再次编译,打包. 需要工具:jd-gui.myeclipse 具体步骤: 1.使用jd-gui打开原始的Jar包,选择File-->Save All S ...
- docker运行jar包_Jenkins+Docker+Springboot单机版持续集成部署
Jenkins+Docker+SpringBoot持续集成流程说明 安装配置jenkins 安装jenkins可直接官网下载对应的jar包直接运行,也可使用docker运行,下载完后直接运行,并下载d ...
- Maven Nexus搭建本地私服 上传jar包或本地项目到私服
Nexus就是Maven的私服 在日常开发中我们在使用maven时经常会遇到下面的问题 1.一些无法从外部仓库下载的构件,例如内部的项目部署到私服上,以便供其他依赖项目使用. 2. 为了节省带宽和时间 ...
- centos运行jar包需要的环境_Centos7服务器下启动jar包项目的最佳方法
前言 在linux上运行jar包谁都会啊.为什么我还要单独拎出来讲呢.细心的朋友可能已经在标题中发现关键词Centos7和最佳方式. 这就说明我不是随便写点东西水一篇博客的ヾ(◍°∇°◍)ノ゙ 首先C ...
- 如何修改可运行Jar包,如何反编译Jar包
将可运行Jar包,反编译成项目,修改代码,再次编译,打包. 需要工具:jd-gui.myeclipse 具体步骤: 1.使用jd-gui打开原始的Jar包,选择File-->Save All ...
- linux 后台运行jar包命令,Linux 运行jar包命令(Cent OS 7后台运行jar包)
Linux 运行jar包命令如下: 方式一 特点:当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出 那如何让窗口不锁定? 方式二 java -jar shareniu. ...
- 【Maven学习】Maven打包生成包含所有依赖的jar包
http://blog.csdn.net/u013177446/article/details/54134583 ******************************************* ...
- java jar 启动项目,SpringBoot项目运行jar包启动的步骤流程解析
SpringBoot项目在开发中,方便快捷,有一点原因就是SpringBoot项目可以打jar包运行:把jar包直接扔服务器上,然后运行jar包就能访问项目接口了.下面介绍SpringBoot项目打j ...
最新文章
- phpmyadmi 上传大文件
- 【PAT (Advanced Level) Practice】1099 Build A Binary Search Tree (30 分)
- 少儿编程python线上课程-北京Python程序开发课程
- 专访《王者荣耀》美术总监:用6年研究东方美学
- java 对象调用_java 对象调用
- c++ cdi+示例_C ++“和”关键字示例
- js常用内建对象之:String对象
- matlab 写入 MYSQL_阿里开源MySQL中间件Canal快速入门
- python实践项目(三)
- matlab中linspace函数用法
- 调研 微信小程序客服功能
- 好心情患者故事:节食暴食反复横跳,我确诊了重度抑郁
- 《矛盾论》与《实践论》
- 十大最佳外国Android游戏下载平台
- 杠杆股票平仓后该如何处理?
- Total Uninstall 6安装使用
- dorado 刷新_记录新建dorado项目更新规则中报错
- Latex 数学符号--双括号
- chrome64的Local Overrides
- 极限运算法则——“高等数学”
热门文章
- 电脑常用音频剪辑软件_如何使用音频剪辑软件,快速剪辑任意格式音频!
- 图像降噪算法——Variance Stabilizing Transform / Generalization Anscombe Transform算法
- TikTok电商2022年英国小店重要节点全览
- 中国新疆保险产业发展动态与投资机遇研究报告2022版
- 全球及中国制糖行业销售规模与运营态势研究报告2022版
- php h5用户信息,【php】PHP怎样防止用户注册高仿其他人的用户名?
- vue 导出 excel表格
- java报错 pom.xml第一行报org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project......
- Python 33(1) UDP协议 数据报协议 socketsever模块
- SpringBoot中使用AOP打印接口日志的方法(转载)