dubbo-admian的打包和平臺搭建
本文簡單介紹下dubbo-admin的搭建過程,包括dubbo-admin的打包細節,以及在打包過程中jdk8的一些坑的解決。
全部程式碼下載:Github連結:github連結,點選驚喜;寫文章不易,歡迎大家採我的文章,以及給出有用的評論,當然大家也可以關注一下我的github;多謝;
1.dubbo-admin介紹:
dubbo-admin從名字可知就是對dubbo進行管理,主要內容包括路由規則,動態配置,服務降級,訪問控制,權重調整,負載均衡,等管理功能。
dubbo的介紹和使用連結
2.下載地址:
3.打包dubbo-admin工程為war
打包其實就是使用maven將dubbo-admin工程變為war可以被Tomact使用的檔案。
3.1.maven和Tomcat安裝:
1.maven安裝:
1.下載我上面的maven軟體
2.然後解壓到特定目錄:apache-maven-3.3.3
3.在path後面追加環境變數:E:\Program Files\eclipse\apache-maven-3.3.3\bin(注意:這是我的地址)
4.測試:在命令視窗下輸入:mvn
2.Tomcat安裝:
1.下載我上面的Tomcat壓縮包
2.直接解壓後就安裝成功
3.2.打包成war檔案
我的jdk8版本和jdk7版本都在之前下載的壓縮檔案中,請各取所需。
1.步驟:
1.開啟命令視窗並cd到dubbo-admin 資料夾(下載的地方)
2.執行mvn package -Dmaven.skip.test=true
打包成功會顯示如下:
打包成功之後,就會發現dubbo-admin下多了個target資料夾,開啟target資料夾,裡面有兩個檔案:1.資料夾dubbo-admin-2.5.4-SNAPSHOT和dubbo-admin-2.5.4-SNAPSHOT.war檔案。兩者都可以放入Tomcat,只需要要放一個。
3.3除錯與執行:
1.啟動ZooKeeperZooKeeper環境搭建
2.將打包後的檔案dubbo-admin-2.5.4-SNAPSHOT.war或者資料夾拷貝到Tomcat的webapps
3.然後到Tomcat的bin目錄下面雙擊startup.bat,啟動後再點選shutdown.bat停止
4.修改webapps下的dubbo-admin-2.5.4-SNAPSHOT/WEB-INF/dubbo.properties的檔案
dubbo.registry.address=zookeeper://127.0.0.1:2181##zk地址
dubbo.admin.root.password=root##root密碼
dubbo.admin.guest.password=guest##guest密碼
5.到Tomcat的bin目錄下面雙擊startup.bat
6. 在瀏覽器輸入http://localhost:8080/dubbo-admin-2.5.4-SNAPSHOT/ 注意:我改了資料夾名為dubbo
7.輸入密碼後:啟動provider和consumer測試,點選服務
如果可以訪問並且顯示,可以不觀看下面,如果報錯下面或許會有幫助
4.錯誤解決:
4.1打包好後放入Tomcat啟動報錯:
1.錯誤:ERROR context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException:
2.主要原因:主要是由於jdk8不能正常執行,切換成jdk8一下的可以執行
3.jdk8解決辦法:
修改pom.xml檔案
1、webx的依賴改為3.1.6版;
<dependency>
<groupId>com.alibaba.citrus</groupId>
<artifactId>citrus-webx-all</artifactId>
<version>3.1.6</version>
</dependency>
2、新增velocity的依賴,我用了1.7;
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
3、對依賴項dubbo新增exclusion,避免引入舊spring
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${project.parent.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
參考於:https://github.com/alibaba/dubbo/issues/50
4.2打包時Maven依賴找不到
1.錯誤:[ERROR] Failed to execute goal on project dubbo-common: Could not resolve dependencies for project
2.原因:dubbo-admin工程下pom.xml中有些jar包不能被公網訪問到
3.解決辦法:
1.根據報的依賴錯修改version
2.下載相應的jar包放到本地倉庫
3.參考網址:https://github.com/alibaba/dubbo/issues/22
4.3我的pom.xml檔案
這個檔案可以被正常打包,jdk8也行
<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>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.5.4-SNAPSHOT</version>
</parent>
<artifactId>dubbo-admin</artifactId>
<packaging>war</packaging>
<name>${project.artifactId}</name>
<description>The admin module of dubbo project</description>
<properties>
<wtpversion>1.5</wtpversion>
<wtpContextName>/</wtpContextName>
<eclipse.useProjectReferences>false</eclipse.useProjectReferences>
<skip_maven_deploy>false</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.citrus</groupId>
<artifactId>citrus-webx-all</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>
<dependency>
<groupId>org.apache.bsf</groupId>
<artifactId>bsf-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.xmemcached</groupId>
<artifactId>xmemcached</artifactId>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
</dependency>
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</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>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>${jetty_version}</version>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>10</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
</project>
本文來自伊豚(blog.wpeace.cn)