Maven构建Dubbo服务可运行的Jar包

Maven构建Dubbo服务可运行的Jar包

  • 1 Dubbo服务提供者的三种启动方式
  • 2 POM文件
  • 3 启动命令
  • 4 服务器部署启动脚本

  

1 Dubbo服务提供者的三种启动方式

Maven构建Dubbo服务可运行的Jar包_第1张图片

2 POM文件


<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>com.testgroupId>
    <artifactId>test-mavenartifactId>
    <version>1.0-SNAPSHOTversion>

    <dependencies>
        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-apiartifactId>
            <version>1.7.28version>
        dependency>
        <dependency>
            <groupId>log4jgroupId>
            <artifactId>log4jartifactId>
            <version>1.2.17version>
        dependency>
    dependencies>

    <build>
        <resources>
           <resources>
			<resource>
				<targetPath>${project.build.directory}/classestargetPath>
				<directory>src/main/resourcesdirectory>
				<filtering>truefiltering>
				<includes>
					<include>**/*.xmlinclude>
					<include>**/*.propertiesinclude>
				includes>
			resource>

			
			
			<resource>
				<targetPath>${project.build.directory}/classes/META-INF/springtargetPath>
				<directory>src/main/resources/springdirectory>
				<filtering>truefiltering>
				<includes>
					<include>spring-context.xmlinclude>
				includes>
			resource>
		resources>
        resources>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                    
                    <encoding>UTF-8encoding>
                configuration>
            plugin>

            
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-jar-pluginartifactId>
                <configuration>
                    <archive>
                        <manifest>
                            
                            <addClasspath>trueaddClasspath>
                            <useUniqueVersions>falseuseUniqueVersions>
                            
                            <classpathPrefix>lib/classpathPrefix>
                            
                            <mainClass>com.alibaba.dubbo.container.MainmainClass>
                        manifest>
                    archive>
                configuration>
            plugin>


            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-dependency-pluginartifactId>
                <executions>
                    <execution>
                        <id>copy-dependenciesid>
                        <phase>packagephase>
                        <goals>
                            <goal>copy-dependenciesgoal>
                        goals>
                        <configuration>
                            
                            <outputDirectory>
                                ${project.build.directory}/lib
                            outputDirectory>
                        configuration>
                    execution>
                executions>
            plugin>
        plugins>
    build>

project>

3 启动命令

通过java -jar 命令启动即可

4 服务器部署启动脚本

#!/bin/sh

## java env
export JAVA_HOME=/usr/local/java/jdk1.7.0_72
export JRE_HOME=$JAVA_HOME/jre

## service name
APP_NAME=user

SERVICE_DIR=/home/wusc/edu/service/$APP_NAME
SERVICE_NAME=edu-service-$APP_NAME
JAR_NAME=$SERVICE_NAME\.jar
PID=$SERVICE_NAME\.pid

cd $SERVICE_DIR

case "$1" in

    start)
        nohup $JRE_HOME/bin/java -Xms256m -Xmx512m -jar $JAR_NAME >/dev/null 2>&1 &
        echo $! > $SERVICE_DIR/$PID
        echo "=== start $SERVICE_NAME"
        ;;

    stop)
        kill `cat $SERVICE_DIR/$PID`
        rm -rf $SERVICE_DIR/$PID
        echo "=== stop $SERVICE_NAME"

        sleep 5
		##
		## edu-service-aa.jar
		## edu-service-aa-bb.jar
        P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "=== $SERVICE_NAME process not exists or stop success"
        else
            echo "=== $SERVICE_NAME process pid is:$P_ID"
            echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID"
            kill -9 $P_ID
        fi
        ;;

    restart)
        $0 stop
        sleep 2
        $0 start
        echo "=== restart $SERVICE_NAME"
        ;;

    *)
        ## restart
        $0 stop
        sleep 2
        $0 start
        ;;

esac
exit 0
service-***  start
service-***  stop
service-***  restart

你可能感兴趣的:(Maven,java)