在上一节中将ODL的开发工具都装好,mvn是生成ODL框架的管理器。在本节中使用mvn构建ODL开发的代码框架。
1|0一、生成ODL代码框架
maven工具根据上一节中设置的setting文件生成ODL的框架代码。使用代码框架的好处是不用从零开始写,框架将基础的代码写好,我们只需要关注自己的业务代码。
mvn archetype:generate –DarchetypeGroupId=org.opendaylight.controller –DarchetypeArtifactId=opendaylight–startup–archetype –DarchetypeVersion=1.3.0–Carbon
root@vm:~# mvn org.apache.maven.plugins:maven–archetype–plugin:2.4:generate –DarchetypeGroupId=org.opendaylight.controller –DarchetypeArtifactId=opendaylight–startup–archetype –DarchetypeRepository=https://nexus.opendaylight.org/content/repositories/public -DarchetypeVersion=1.3.2-Carbon
[INFO] Scanning for projects…
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.pom (9 KB at 2.7 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/archetype/maven-archetype/2.4/maven-archetype-2.4.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/archetype/maven-archetype/2.4/maven-archetype-2.4.pom (13 KB at 22.8 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/maven-parent/26/maven-parent-26.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/maven-parent/26/maven-parent-26.pom (39 KB at 46.9 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/apache/16/apache-16.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/apache/16/apache-16.pom (16 KB at 27.5 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.jar
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.jar (92 KB at 105.9 KB/sec)
[INFO]
[INFO] ————————————————————————
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ————————————————————————
[INFO]
[INFO] >>> maven–archetype–plugin:2.4:generate (default–cli) > generate–sources @ standalone–pom >>>
[INFO]
[INFO] <<< maven–archetype–plugin:2.4:generate (default–cli) < generate–sources @ standalone–pom <<<
[INFO]
[INFO] — maven–archetype–plugin:2.4:generate (default–cli) @ standalone–pom —
[INFO] Scanning for projects…
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.pom (9 KB at 2.7 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/archetype/maven-archetype/2.4/maven-archetype-2.4.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/archetype/maven-archetype/2.4/maven-archetype-2.4.pom (13 KB at 22.8 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/maven-parent/26/maven-parent-26.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/maven-parent/26/maven-parent-26.pom (39 KB at 46.9 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/apache/16/apache-16.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/apache/16/apache-16.pom (16 KB at 27.5 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.jar
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.jar (92 KB at 105.9 KB/sec)
[INFO]
[INFO] ————————————————————————
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ————————————————————————
[INFO]
[INFO] >>> maven–archetype–plugin:2.4:generate (default–cli) > generate–sources @ standalone–pom >>>
[INFO]
[INFO] <<< maven–archetype–plugin:2.4:generate (default–cli) < generate–sources @ standalone–pom <<<
[INFO]
[INFO] — maven–archetype–plugin:2.4:generate (default–cli) @ standalone–pom —
Define value for property ‘groupId’: : org.opendaylight.example
Define value for property ‘artifactId’: : example
[INFO] Using property: version = 0.1.0–SNAPSHOT
Define value for property ‘package’: org.opendaylight.topology: :
Jul 12, 2019 2:36:35 PM org.apache.velocity.runtime.log.JdkLogChute log
INFO: FileResourceLoader : adding path ‘.’
Define value for property ‘classPrefix’: Topology: :
Define value for property ‘copyright’: : worker
[INFO] Using property: copyrightYear = 2017
Confirm properties configuration:
groupId: org.opendaylight.topology
artifactId: topology
version: 0.1.0–SNAPSHOT
package: org.opendaylight.topology
classPrefix: Topology
copyright: worker
copyrightYear: 2017
Y: : y
Define value for property ‘artifactId’: : example
[INFO] Using property: version = 0.1.0–SNAPSHOT
Define value for property ‘package’: org.opendaylight.topology: :
Jul 12, 2019 2:36:35 PM org.apache.velocity.runtime.log.JdkLogChute log
INFO: FileResourceLoader : adding path ‘.’
Define value for property ‘classPrefix’: Topology: :
Define value for property ‘copyright’: : worker
[INFO] Using property: copyrightYear = 2017
Confirm properties configuration:
groupId: org.opendaylight.topology
artifactId: topology
version: 0.1.0–SNAPSHOT
package: org.opendaylight.topology
classPrefix: Topology
copyright: worker
copyrightYear: 2017
Y: : y
[INFO] —————————————————————————-
[INFO] Using following parameters for creating project from Archetype: opendaylight–startup–archetype:1.3.2–Carbon
[INFO] —————————————————————————-
[INFO] Parameter: groupId, Value: org.opendaylight.topology
[INFO] Parameter: artifactId, Value: topology
[INFO] Parameter: version, Value: 0.1.0–SNAPSHOT
[INFO] Parameter: package, Value: org.opendaylight.topology
[INFO] Parameter: packageInPathFormat, Value: org/opendaylight/topology
[INFO] Parameter: classPrefix, Value: Topology
[INFO] Parameter: package, Value: org.opendaylight.topology
[INFO] Parameter: version, Value: 0.1.0–SNAPSHOT
[INFO] Parameter: copyright, Value: worker
[INFO] Parameter: groupId, Value: org.opendaylight.topology
[INFO] Parameter: artifactId, Value: topology
[INFO] Parameter: copyrightYear, Value: 2017
[WARNING] Don‘t override file /root/topology/pom.xml
[INFO] project created from Archetype in dir: /root/topology
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 03:53 min
[INFO] Finished at: 2019-07-12T14:36:59+08:00
[INFO] Final Memory: 16M/38M
[INFO] ————————————————————————
[INFO] Using following parameters for creating project from Archetype: opendaylight–startup–archetype:1.3.2–Carbon
[INFO] —————————————————————————-
[INFO] Parameter: groupId, Value: org.opendaylight.topology
[INFO] Parameter: artifactId, Value: topology
[INFO] Parameter: version, Value: 0.1.0–SNAPSHOT
[INFO] Parameter: package, Value: org.opendaylight.topology
[INFO] Parameter: packageInPathFormat, Value: org/opendaylight/topology
[INFO] Parameter: classPrefix, Value: Topology
[INFO] Parameter: package, Value: org.opendaylight.topology
[INFO] Parameter: version, Value: 0.1.0–SNAPSHOT
[INFO] Parameter: copyright, Value: worker
[INFO] Parameter: groupId, Value: org.opendaylight.topology
[INFO] Parameter: artifactId, Value: topology
[INFO] Parameter: copyrightYear, Value: 2017
[WARNING] Don‘t override file /root/topology/pom.xml
[INFO] project created from Archetype in dir: /root/topology
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 03:53 min
[INFO] Finished at: 2019-07-12T14:36:59+08:00
[INFO] Final Memory: 16M/38M
[INFO] ————————————————————————
当命令执行结束之后,会生成一个ODL的代码框架。具体内容有如下:
文件名 | 功能 |
api | Yang模型目录 |
artifacts | 项目组件坐标管理 |
cli | 部署的配置文件 |
features | feature组织管理目录 |
impl | 业务逻辑的代码实现目录 |
it | 集成测试 |
karaf | karaf打包目录 |
pom.xml | maven项目的基本信息描述文件 |
2|0二、编译ODL框架代码
将ODL框架代码编译之后就能运能一个最简单的ODL控制器,该控制器没有任何多余功能。
提示:这个过程会持续半个小时以上时间,并且可能会连接超时而报错,具体长短取决于你的机器性能和网络。确保你在执行这个动作之前是在工程的根目录下。
mvn clean install –DskipTests –Dmaven.javadoc.skip=true –Dcheckstyle.skip=true
参数:
-DskipTests表示不执行测试用例
-Dmaven.javadoc.skip=true表示跳过javadoc
-Dcheckstyle.skip=true表示跳过checkstyle检查
root@vm:~/topology# pwd
/root/example
root@vm:~/topology# mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
[INFO] Scanning for projects…
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent/1.8.2-Carbon/odlparent-1.8.2-Carbon.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent/1.8.2-Carbon/odlparent-1.8.2-Carbon.pom (77 KB at 26.6 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent-lite/1.8.2-Carbon/odlparent-lite-1.8.2-Carbon.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent-lite/1.8.2-Carbon/odlparent-lite-1.8.2-Carbon.pom (18 KB at 30.4 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/mdsal/binding-parent/0.10.2-Carbon/binding-parent-0.10.2-Carbon.pom
/root/example
root@vm:~/topology# mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
[INFO] Scanning for projects…
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent/1.8.2-Carbon/odlparent-1.8.2-Carbon.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent/1.8.2-Carbon/odlparent-1.8.2-Carbon.pom (77 KB at 26.6 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent-lite/1.8.2-Carbon/odlparent-lite-1.8.2-Carbon.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent-lite/1.8.2-Carbon/odlparent-lite-1.8.2-Carbon.pom (18 KB at 30.4 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/mdsal/binding-parent/0.10.2-Carbon/binding-parent-0.10.2-Carbon.pom
[INFO] Feature repository discovered recursively: standard–3.0.8
[INFO] Feature repository discovered recursively: enterprise–3.0.8
[INFO] Feature repository discovered recursively: org.ops4j.pax.web–3.2.9
[INFO] Feature repository discovered recursively: spring–3.0.8
[INFO] Feature repository discovered recursively: odl–topology–0.1.0–SNAPSHOT
[INFO] Feature repository discovered recursively: odl–topology–0.1.0–SNAPSHOT
[INFO] Feature repository discovered recursively: odl–yangtools–1.1.2–Carbon
[INFO] Feature repository discovered recursively: odlparent–1.8.2–Carbon
[INFO] Feature repository discovered recursively: odl–netty–4
[INFO] Feature repository discovered recursively: odl–guava–18
[INFO] Feature repository discovered recursively: odl–guava–21
[INFO] Feature repository discovered recursively: odl–lmax–3
[INFO] Feature repository discovered recursively: odl–triemap–0.2
[INFO] Feature repository discovered recursively: odl–mdsal–models–0.10.2–Carbon
[INFO] Feature repository discovered recursively: odl–yangtools–2.2.2–Carbon
[INFO] Feature repository discovered recursively: odl–mdsal–1.5.2–Carbon
[INFO] Feature repository discovered recursively:
[INFO] Feature repository discovered recursively: enterprise–3.0.8
[INFO] Feature repository discovered recursively: org.ops4j.pax.web–3.2.9
[INFO] Feature repository discovered recursively: spring–3.0.8
[INFO] Feature repository discovered recursively: odl–topology–0.1.0–SNAPSHOT
[INFO] Feature repository discovered recursively: odl–topology–0.1.0–SNAPSHOT
[INFO] Feature repository discovered recursively: odl–yangtools–1.1.2–Carbon
[INFO] Feature repository discovered recursively: odlparent–1.8.2–Carbon
[INFO] Feature repository discovered recursively: odl–netty–4
[INFO] Feature repository discovered recursively: odl–guava–18
[INFO] Feature repository discovered recursively: odl–guava–21
[INFO] Feature repository discovered recursively: odl–lmax–3
[INFO] Feature repository discovered recursively: odl–triemap–0.2
[INFO] Feature repository discovered recursively: odl–mdsal–models–0.10.2–Carbon
[INFO] Feature repository discovered recursively: odl–yangtools–2.2.2–Carbon
[INFO] Feature repository discovered recursively: odl–mdsal–1.5.2–Carbon
[INFO] Feature repository discovered recursively: