本文以dubbo2.4.11源碼編譯和打包例java
dubbo官網:http://dubbo.io/git
源碼:https://github.com/alibaba/dubbogithub
用戶指南:http://dubbo.io/User+Guide-zh.htmweb
開發指南:http://dubbo.io/Developer+Guide-zh.htmjson
按官方說明2.4.X是GA穩定版本,去https://github.com/alibaba/dubbo/releases下載最新的2.4.11tomcat
解壓到D:\project\dubbo\dubbo-dubbo-2.4.11app
在編譯dubbo前,先執行下面操做eclipse
1、opensesame依賴問題,可能會報Non-resolvable parent POM: Could not transfer artifact com.alibaba:opensesame:pom:2.0 from/to opensesame.releases (http://code.alibabatech.com/mvn/releases)webapp
的錯誤。maven
打開https://github.com/alibaba/opensesame,下載opensesame(主要是pom.xml文件),解壓在D:\project\dubbo\opensesame-master目錄
在D:\project\dubbo\opensesame-master目錄下,cmd命令行執行
mvn clean install -Dmaven.test.skip
編譯完成後,修改D:\project\dubbo\opensesame-master\pom.xml,把版本2.0修改成1.0,
<groupId>com.alibaba</groupId> <artifactId>opensesame</artifactId> <!-- 2.0修改成1.0 --> <version>1.0</version> <packaging>pom</packaging>
相同目錄再編譯一次opensesame
mvn clean install -Dmaven.test.skip
2、fastjson依賴包,可能報[ERROR] Failed to execute goal on project dubbo-common: Could not resolve dependencies for project com.alibaba:dubbo-common:jar:2.5.4-SNAPSHOT: Could not find artifact com.alibaba:fastjson:jar:1.1.8 in ibiblio.org (http://mirrors.ibiblio.org/pub/mirrors/maven2) -> [Help 1]錯誤
修改D:\project\dubbo\dubbo-dubbo-2.4.11\pom.xml,找到 <fastjson_version>1.1.8</fastjson_version>,將1.1.8修改成1.1.39,參考https://github.com/alibaba/dubbo/issues/22
3、註釋D:\project\dubbo\dubbo-dubbo-2.4.11\pom.xml下邊的內容
<repositories> <repository> <id>opensesame.releases</id> <url>http://code.alibabatech.com/mvn/releases</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories>
4、hessian-lite依賴包,Unable to find resource 'com.alibaba:hessian-lite:jar:3.2.1-fixed-2' in repository central.repo (http://repo1.maven.org/maven2)
從github的dubbo主庫中下載hessian-lite,當前最新的dubbo源碼中已帶有hessian-lite源碼,能夠直接取出來加到dubbo 2.4.11中編譯(https://github.com/alibaba/dubbo,https://github.com/alibaba/dubbo/tree/master/hessian-lite)
把hessian-lite拷貝到D:\project\dubbo\dubbo-dubbo-2.4.11,
修改D:\project\dubbo\dubbo-dubbo-2.4.11\pom.xml,增長<module>hessian-lite</module>編譯
<modules> <!-- 增長 hessian-lite--> <module>hessian-lite</module> <module>dubbo-common</module> <module>dubbo-container</module> <module>dubbo-remoting</module> <module>dubbo-rpc</module> <module>dubbo-filter</module> <module>dubbo-cluster</module> <module>dubbo-registry</module> <module>dubbo-monitor</module> <module>dubbo-config</module> <module>dubbo</module> </modules>
修改D:\project\dubbo\dubbo-2.4.11\hessian-lite\pom.xml
<parent> <groupId>com.alibaba</groupId> <artifactId>dubbo-parent</artifactId> <!--<version>2.5.4-SNAPSHOT</version> 把版本號改成2.4.11,須要與當前dubbo版本號一致--> <version>2.4.11</version> </parent>
5、增長編譯dubbo管理控制檯,這一步不是必須的,主要是官方的dubbo管理控制檯下載不了,直接本身編譯一個,默認下不編譯打包dubbo-admin,須要本身增長。
修改D:\project\dubbo\dubbo-2.4.11\dubbo-admin\pom.xml文件,把版本號改成2.4.11
<parent> <groupId>com.alibaba</groupId> <artifactId>dubbo-parent</artifactId> <!-- <version>2.4.10</version> 版本號修改成2.4.11 --> <version>2.4.11</version> </parent>
修改D:\project\dubbo\dubbo-dubbo-2.4.11\pom.xml,增長<module>dubbo-admin</module>編譯
<modules> <module>hessian-lite</module> <module>dubbo-common</module> <module>dubbo-container</module> <module>dubbo-remoting</module> <module>dubbo-rpc</module> <module>dubbo-filter</module> <module>dubbo-cluster</module> <module>dubbo-registry</module> <module>dubbo-monitor</module> <module>dubbo-config</module> <module>dubbo</module> <!-- 增長編譯dubbo-admin管理控制檯,dubbo-simple、dubbo-demo可自行決定是否編譯 --> <module>dubbo-admin</module> </modules>
6、正式編譯dubbo
1)cmd命令行,在D:\project\dubbo\dubbo-dubbo-2.4.11目錄下執行命令:
先設置maven內存,不然編譯時會報內存不足錯誤
set MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=512m mvn clean install -Dmaven.test.skip
7、添加eclipse支持
在D:\project\dubbo\dubbo-dubbo-2.4.11目錄下執行命令:
mvn eclipse:eclipse
能夠直接在eclipse運行下邊幾個程序
dubbo-demo-provider/src/test/java/com.alibaba.dubbo.demo.provider.DemoProvider
dubbo-demo-consumer/src/test/java/com.alibaba.dubbo.demo.consumer.DemoConsumer
dubbo-monitor-simple/src/test/java/com.alibaba.dubbo.monitor.simple.SimpleMonitor
dubbo-registry-simple/src/test/java/com.alibaba.dubbo.registry.simple.SimpleRegistry
8、dubbo-admin管理控制檯安裝
第6步執行完成後,D:\project\dubbo\dubbo-2.4.11\dubbo-admin\target目錄會生成dubbo-admin-2.4.11.war,
war包解壓到webapps/ROOT目錄下,修改WEB-INF\dubbo.properties,
dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.admin.root.password=root dubbo.admin.guest.password=guest
dubbo.properties配置zookeeper的註冊中心地址(zookeeper的安裝配置忽略)
注意:肯定zookeeper啓動後再去啓動tomcat。