opendaylight-Boron-SR3开发入门实例

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/songqiu65/article/details/76037305

开发环境搭建:
开发环境配置如下:
1) 64位ubuntu16.04系统,4G以上内存, 16G以上硬盘剩余空间
2) JDK8, maven-3.5.0(源码安装)
3) 环境变量设置(gedit /etc/profilesource /etc/profile)

export JAVA_HOME=…
export MAVEN_OPTS="-Xmx4G"

注:MAVEN_OPTS是设置内存的(内存小给1024m),java是sudo apt-get install oracle-java8-installer 安装的就可以不用填export JAVA_HOME=…

开发示例项目(默认hello):
0) 获取ODL的maven配置文件(用于maven编译时下载ODL的相应jar文件)

wget -q -O  -  https://raw.githubusercontent.com/opendaylight/odlparent/stable/boron/settings.xml  >   ~/.m2/settings.xml

注:关于.m2文件夹:
安装完maven是没有.m2文件夹的。在Linux中以.开头的文件夹都是隐藏的。当使用maven命令(例如mvn help:system)的时候,maven自动会创建.m2文件夹(可用ll查看)。
1.repository
所有的maven构件,都存储在repository中。比如本机中的使用maven的项目所以来的jar包,下载后都会存放在此处。
2.settings.xml
settings.xml存在maven根目录下conf中,安装maven后其实是根本不存在的。
1) 用maven生成项目框架(设项目为hello)
说明:
对于Boron SR0,使用Archetype-Version = 1.2.0-Boron
对于Boron SR1,使用Archetype-Version = 1.2.1-Boron-SR1
对于Boron SR2,使用Archetype-Version = 1.2.2-Boron-SR2
按版本修改下面第一个命令中的DarchetypeVersion

# mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype \
-DarchetypeRepository=http://nexus.opendaylight.org/content/repositories/opendaylight.release/ \
-DarchetypeCatalog=remote -DarchetypeVersion=1.2.3-Boron-SR3
#
Define value for property 'groupId': org.bupt.siwind.hello
Define value for property 'artifactId': hello
Define value for property 'package':  org.bupt.siwind.hello: : (回车)
Define value for property 'classPrefix':  (回车)
Define value for property 'copyright': : Pn, Inc. 

Y: :  (回车)

2) 编译运行

cd hello/
mvn clean install

注:文件在/.m2/repository/org/bupt/

#./karaf/target/assembly/bin/karaf
opendaylight-user@root>feature:list -i | grep hello
opendaylight-user@root>log:display | grep Hello

可以看到hello已经安装。

3) 将hello安装到生产odl中
i)拷贝:假设当前正常部署运行的ODL发行版位于: /opt/distribution-karaf-0.5.3-Boron-SR3

当前的hello项目位于/root/hello

那么拷贝命令如下:

#cp -R /root/hello/karaf/target/assembly/system/org/bupt /opt/distribution-karaf-0.5.3-Boron-SR3/system/org

ii)查看hello的maven路径:

#cd hello (进入hello项目目录)
#cat ./karaf/target/assembly/etc/org.apache.karaf.features.cfg

查看这一行:featuresRepositories
在最后有hello的mvn路径: mvn:org.bupt.siwind.hello/hello-features/0.1.0-SNAPSHOT/xml/features

iii)运行ODL并添加和安装hello的bundle:

#cd /opt/distribution-karaf-0.5.3-Boron-SR3
#./bin/karaf (启动ODL运行,或者以干净模式启动: ./bin/karaf clean)
#opendaylight@root>feature:repo-add mvn:org.bupt.siwind.hello/hello-features/0.1.0-SNAPSHOT/xml/features
# opendaylight@root>feature:install odl-hello-ui
# opendaylight@root> feature:list| grep hello
# opendaylight@root> log:display| grep Hello

可以看到运行结果正常。
(移除bundle)

#opendaylight@root>feature:repo-remove mvn:org.bupt.siwind.hello/hello-features/0.1.0-SNAPSHOT/xml/features

参考资料

猜你喜欢

转载自blog.csdn.net/songqiu65/article/details/76037305
sr