maven构建dubbo服务的可执行jar包

dubbo提供者服务使用dubbo框架提供的Main方法类来运行:
dubbo框架提供:com.alibaba.dubbo.container.Main(可实现优雅关机ShutdownHook)


在提供者的pom.xml中配置以下maven插件:

<build>
        <finalName>dubbo-provider</finalName>  <!-- jar包名,一般设置为提供者服务名 -->

        <resources>
            <!-- 把resource目录下所有文件和文件夹导入到jar包内 -->
            <resource>
                <targetPath>${project.build.directory}/classes</targetPath>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <!-- 可直接写为<include>**/*</include>包含所有文件 -->
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <!-- 使用com.alibaba.dubbo.container.Main启动spring容器,会默认加载META-INF/spring目录下的所有spring配置 -->
            <resource>
                <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
                <directory>src/main/resources/spring</directory>
                <filtering>true</filtering>
                <!-- 把src/main/resources/spring路径下的spring配置文件拷贝到${project.build.directory}/classes/META-INF/spring下 -->
                <includes>
                    <include>spring-application.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>
            <!-- maven打包成jar的插件 -->
            <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <!-- 把target/classes/下的文件导入到jar内 -->
                    <classesDirectory>target/classes/</classesDirectory>
                    <archive>
                        <manifest>
                            <!-- 指定程序入口 -->
                            <mainClass>com.alibaba.dubbo.container.Main</mainClass>
                            <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
                            <useUniqueVersions>false</useUniqueVersions>
                            <addClasspath>true</addClasspath>
                            <!-- 服务依赖的jar包放在lib目录下 -->
                            <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>
                            <!-- 存放服务依赖的jar包,存放在服务相同目录的lib文件夹下 -->
                            <outputDirectory>
                                ${project.build.directory}/lib
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

注意在spring-application.xml中引入其他配置文件时要写为:

<import resource="classpath:spring/spring-mybatis.xml" />
    <import resource="classpath:spring/dubbo-provider.xml" />

因为spring-application.xml会被加载到${project.build.directory}/classes/META-INF/spring下,而不与引入的配置文件在同一目录下。


在对dubbo-provider服务打包成jar之前(maven install),需要将dubbo-provider服务依赖的工程先打包,在本地maven仓库生成相应的jar,这样dubbo-provider服务才会打包成功。最终在项目target目录下会生成lib文件夹和dubbo-provider.jar。lib文件夹存放的是dubbo-provider服务依赖的jar。
注:dubbo-provider.jar为什么能引用到lib文件夹内的jar,是因为dubbo-provider.jar的META-INF/MANIFEST.MF配置文件内说明了dubbo-provider服务依赖的jar。


运行dubbo-provider.jar:打开命令控制器,在dubbo-provider.jar所在的目录下输入java -jar dubbo-provider.jar & ,回车,出现下面的界面即运行成功:
这里写图片描述
管控台上成功显示提供者:
这里写图片描述

ant-1.6.2.jar asm-analysis-3.2.jar asm-commons-3.2.jar asm-tree-3.2.jar asm-util-3.2.jar aspectjweaver-1.7.4.jar avalon-framework-4.1.3.jar bsf-api-3.1.jar cache-api-0.4.jar cglib-nodep-2.2.jar citrus-webx-all-3.0.8.jar classworlds-1.1-alpha-2.jar classworlds-1.1.jar commons-beanutils.jar commons-cli-1.0.jar commons-collections-3.2.jar commons-digester-1.6.jar commons-httpclient-2.0.2.jar commons-io-1.3.2.jar commons-io-2.1.jar commons-lang-2.5.jar commons-logging-1.1.jar commons-validator-1.2.0.jar curator-framework-1.1.16.jar cxf-rt-frontend-simple-2.6.1.jar cxf-rt-transports-http-2.6.1.jar doxia-core-1.0-alpha-11.jar doxia-core-1.0.jar doxia-decoration-model-1.0-alpha-11.jar doxia-decoration-model-1.0.jar doxia-module-apt-1.0-alpha-11.jar doxia-module-apt-1.0.jar doxia-module-fml-1.0-alpha-11.jar doxia-module-fml-1.0.jar doxia-module-xdoc-1.0-alpha-11.jar doxia-module-xdoc-1.0.jar doxia-module-xhtml-1.0-alpha-11.jar doxia-module-xhtml-1.0.jar doxia-sink-api-1.0-alpha-10.jar doxia-sink-api-1.0-alpha-11.jar doxia-sink-api-1.0-alpha-4.jar doxia-sink-api-1.0.jar doxia-site-renderer-1.0-alpha-11.jar doxia-site-renderer-1.0.jar dummy.jar.zip dummy1.0.jar easymock-1.2_Java1.3.jar easymock-3.0.jar easymockclassextension-3.0.jar fastjson-1.1.31.jar fastjson-1.2.28.jar fastjson-1.2.31.jar file-management-1.2.1.jar fst-1.55.jar grizzly-core-2.1.4.jar hessian-lite-3.2.1-fixed-2.jar hibernate-validator-4.2.0.Final.jar hsqldb-1.7.1.jar htmlunit-1.9.jar httpclient-4.0.1.jar httpclient-4.1.2.jar httpclient-4.2.5.jar httpclient-4.4.jar httpcore-4.0.1.jar httpcore-4.1.2.jar jackson-core-2.8.8.jar jackson-core-asl-1.9.13.jar jackson-databind-2.3.3.jar jackson-datatype-joda-2.4.0.jar jackson-mapper-asl-1.9.12.jar javassist-3.20.0-GA.jar javax.ws.rs-api-2.0.1.jar jaxen-core-1.0-FCS.jar jaxen-jdom-1.0-FCS.jar jdependency-0.6.jar jdom-1.1.jar jedis-2.1.0.jar jetty-4.2.10.jar jetty-4.2.12.jar jfreechart-1.0.13.jar jmockit-0.999.8.jar jsch-0.1.23.jar jsch-0.1.27.jar jsr305-2.0.1.jar jtid
dubbox 修改了kryo序列问题 at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:190) at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:110) at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:84) at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:96) at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:144) at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:74) at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75) at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) at com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:53) at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:48) at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53) at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:77) at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:227) at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:72) at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52) at com.alibaba.dubbo.common.bytecode.proxy1.test(proxy1.java)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值