dubbo打包部署配置

最近在做项目部署,参照dubbo.io的示例写了两个接口,简单地返回两个字符串,这里就不详述dubbo配置了,详情请参考dubbo官网。

public class SystemServiceImpl implements SystemService {

    public String getSystemName() {
        return "blog-app";
    }

}
public class HelloServiceImpl implements HelloService {

    public String sayHello(String name) {
        return "hello " + name;
    }

}

代码编写好以后,需要导成jar包放到linux中部署,导包使用maven相关配置

<build>  
    <finalName>service-blogfinalName>  

    <resources>  
        <resource>  
            <targetPath>${project.build.directory}/classestargetPath>  
            <directory>src/main/resourcesdirectory>  
            <filtering>truefiltering>  
            <includes>  
                <include>blog-provider.xmlinclude>  
                <include>**/*.propertiesinclude>  
            includes>  
        resource>  
        
        <resource>  
            <targetPath>${project.build.directory}/classes/META-INF/springtargetPath>  
            <directory>src/main/resourcesdirectory>  
            <filtering>truefiltering>  
            <includes>  
                <include>blog-provider.xmlinclude>   
            includes>  
        resource>  
    resources>  

    <pluginManagement>  
        <plugins>  
            
            <plugin>  
                <groupId>org.eclipse.m2egroupId>  
                <artifactId>lifecycle-mappingartifactId>  
                <version>1.0.0version>  
                <configuration>  
                    <lifecycleMappingMetadata>  
                        <pluginExecutions>  
                            <pluginExecution>  
                                <pluginExecutionFilter>  
                                    <groupId>org.apache.maven.pluginsgroupId>  
                                    <artifactId>maven-dependency-pluginartifactId>  
                                    <versionRange>[2.0,)versionRange>   
                                    <goals>  
                                        <goal>copy-dependenciesgoal>  
                                    goals>  
                                pluginExecutionFilter>  
                                <action>  
                                    <ignore />  
                                action>  
                            pluginExecution>  
                        pluginExecutions>  
                    lifecycleMappingMetadata>  
                configuration>  
            plugin>  
        plugins>  
    pluginManagement>  
    <plugins>  
      
        <plugin>  
            <groupId>org.apache.maven.pluginsgroupId>  
            <artifactId>maven-jar-pluginartifactId>  
            <configuration>  
                <classesDirectory>target/classes/classesDirectory>  
                <archive>  
                    <manifest>  
                        <mainClass>com.alibaba.dubbo.container.MainmainClass>  
                        
                        <useUniqueVersions>falseuseUniqueVersions>  
                        <addClasspath>trueaddClasspath>  
                        <classpathPrefix>lib/classpathPrefix>  
                    manifest>  
                    <manifestEntries>  
                        <Class-Path>.Class-Path>  
                    manifestEntries>  
                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>  
                        <type>jartype>  
                        <includeTypes>jarincludeTypes>  
                        <useUniqueVersions>falseuseUniqueVersions>  
                        <outputDirectory>  
                            ${project.build.directory}/lib  
                        outputDirectory>  
                    configuration>  
                execution>  
            executions>  
        plugin>   

    plugins>  
build> 

其中blog-provider.xml是项目的配置文件,如果项目有多个配置文件,可以写成*.xml,install后把生成的target/lib目录及内容以及生成的本项目jar包,这里命名为service-blog.jar放到linux中的同一目录下
dubbo打包部署配置_第1张图片
到这就可以使用java命令启动了,先启动zookeeper,然后使用java -jar service-blog.jar启动provider
dubbo打包部署配置_第2张图片
切换到zookeeper的bin目录,运行./zkCli.sh -server localhost:2181,配合ls /命令查看dubbo服务(当然也可以使用dubbo-admin)
dubbo打包部署配置_第3张图片
dubbo打包部署配置_第4张图片
还有更优雅的配置方法,可以install后生成shell命令,以及使用jenkins自动部署,以后如果有空再找找资料

你可能感兴趣的:(dubbo打包部署配置)