dubbo-executable jar package using MAVEN to build Dubbo services

Source: Internet
Author: User

First, why build the executable jar package for the Dubbo service?

  1.1 Dubbo Service Operating mode comparison

? Run with the servlet container (Tomcat, jetty, etc.)--- not available

- Cons: increased complexity (more ports for containers)

Waste memory resources, servlet runs to occupy a certain amount of memory

The self-built main () method to run the Spring container--- is not available (local debugging is free)

- Disadvantage:The advanced features provided by Dubbo itself are useless

Writing startup classes yourself can be flawed

? Use the Dubbo framework to provide the main () method to run the Spring container--- recommended

--Advantages: provided by the framework itself (Com.alibaba.dubbo.container.Main)

Graceful shutdown Possible (Shutdownhook)

  1.2 Official Document View

Http://dubbo.io/books/dubbo-user-book/demos/service-container.html

"6.40 Container Service " section

  so to build the executable jar package for the Dubbo service (Say a nonsense, steal laughter!!) )

Second, how to build?

  2.1 See the Project catalogue

This is the project we're going to pack into a Dubbo service.

  2.2 Maven Plugin

<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>  <!--combined with Com.alibaba.dubbo.container.Main -  <Resource>
   <!--to package files under the Resources/spring directory into the classpath metainf/spring directory-- <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> <!--resolves a series of lifecycle-induced conflicts in the MAVEN plug-in implemented within 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> <!--when packaging a jar file, configure the manifest file to include the jar dependency of the Lib package - <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 when packing. MF file does not record the timestamp version - <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>

  2.3 Maven Package

    MVN Clean Package

  And then you can see it in the target directory of the project.

  

Open the Edu-service-user.jar directory and look at the structure.

  2.4 Running the jar package:

Run Java-jar Edu-service-user.jar in the directory of the jar file

  2.4 Points of attention:

Add "classpath:" where import introduces other XML configuration files.

Dubbo-an executable jar package that uses MAVEN to build Dubbo services

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.