从零开始学OpenDaylight之使用Archetype构建项目

Posted 水共禾刀

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从零开始学OpenDaylight之使用Archetype构建项目相关的知识,希望对你有一定的参考价值。

本文源自https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Startup_Project_Archetype Part1

一、环境信息:

     Windows 10 + maven3.3.9 + JDK1.8,详细信息如下:     

<properties>
    <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
    <property name="sun.boot.library.path" value="C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\bin"/>
    <property name="java.vm.version" value="25.121-b13"/>
    <property name="java.vm.vendor" value="Oracle Corporation"/>
    <property name="maven.multiModuleProjectDirectory" value="D:\\CODE\\odlexample\\example1\\example"/>
    <property name="java.vendor.url" value="http://java.oracle.com/"/>
    <property name="path.separator" value=";"/>
    <property name="guice.disable.misplaced.annotation.check" value="true"/>
    <property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
    <property name="file.encoding.pkg" value="sun.io"/>
    <property name="user.script" value=""/>
    <property name="user.country" value="CN"/>
    <property name="sun.java.launcher" value="SUN_STANDARD"/>
    <property name="sun.os.patch.level" value=""/>
    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
    <property name="user.dir" value="D:\\CODE\\odlexample\\example1\\example"/>
    <property name="java.runtime.version" value="1.8.0_121-b13"/>
    <property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/>
    <property name="java.endorsed.dirs" value="C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\endorsed"/>
    <property name="os.arch" value="amd64"/>
    <property name="java.io.tmpdir" value="C:\\Users\\root\\AppData\\Local\\Temp\\"/>
    <property name="line.separator" value="&#10;"/>
    <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
    <property name="user.variant" value=""/>
    <property name="os.name" value="Windows 10"/>
    <property name="classworlds.conf" value="D:\\soft\\apache-maven-3.3.9\\bin\\..\\bin\\m2.conf"/>
    <property name="sun.jnu.encoding" value="GBK"/>
    <property name="java.library.path" value="C:\\Program Files\\Java\\jdk1.8.0_121\\bin;C:\\Windows\\Sun\\Java\\bin;C:\\Windows\\system32;C:\\Windows;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Program Files\\VanDyke Software\\Clients\\;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;D:\\soft\\apache-maven-3.3.9\\bin;C:\\Program Files\\Java\\jdk1.8.0_121\\bin;C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\bin;C:\\Users\\root\\AppData\\Local\\Microsoft\\WindowsApps;;."/>
    <property name="java.specification.name" value="Java Platform API Specification"/>
    <property name="java.class.version" value="52.0"/>
    <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
    <property name="maven.test.failure.ignore" value="true"/>
    <property name="os.version" value="10.0"/>
    <property name="user.home" value="C:\\Users\\root"/>
    <property name="user.timezone" value="Asia/Shanghai"/>
    <property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/>
    <property name="java.specification.version" value="1.8"/>
    <property name="file.encoding" value="GBK"/>
    <property name="user.name" value="root"/>
    <property name="java.class.path" value="D:\\soft\\apache-maven-3.3.9\\bin\\..\\boot\\plexus-classworlds-2.5.2.jar"/>
    <property name="java.vm.specification.version" value="1.8"/>
    <property name="sun.arch.data.model" value="64"/>
    <property name="java.home" value="C:\\Program Files\\Java\\jdk1.8.0_121\\jre"/>
    <property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher clean install -Dmaven.test.failure.ignore=true"/>
    <property name="java.specification.vendor" value="Oracle Corporation"/>
    <property name="user.language" value="zh"/>
    <property name="awt.toolkit" value="sun.awt.windows.WToolkit"/>
    <property name="java.vm.info" value="mixed mode"/>
    <property name="java.version" value="1.8.0_121"/>
    <property name="java.ext.dirs" value="C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\ext;C:\\Windows\\Sun\\Java\\lib\\ext"/>
    <property name="sun.boot.class.path" value="C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\resources.jar;C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\rt.jar;C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\sunrsasign.jar;C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\jsse.jar;C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\jce.jar;C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\charsets.jar;C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\lib\\jfr.jar;C:\\Program Files\\Java\\jdk1.8.0_121\\jre\\classes"/>
    <property name="sun.stderr.encoding" value="ms936"/>
    <property name="java.vendor" value="Oracle Corporation"/>
    <property name="maven.home" value="D:\\soft\\apache-maven-3.3.9\\bin\\.."/>
    <property name="file.separator" value="\\"/>
    <property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
    <property name="sun.cpu.endian" value="little"/>
    <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
    <property name="sun.stdout.encoding" value="ms936"/>
    <property name="sun.desktop" value="windows"/>
    <property name="sun.cpu.isalist" value="amd64"/>
  </properties>

 

二、使用Archetype构建项目过程     

1. 使用Archetype构建基于openDaylight-carbon版本的项目

mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeRepository=http://nexus.opendaylight.org/content/repositories/opendaylight.release -DarchetypeCatalog=remote -DarchetypeVersion=1.3.0-Carbon

 并在后续的提示框中输入相关的值:

 生成的目录结构树如下所示(tree命令)

example
    ├─api
    │  └─src
    │      └─main
    │          └─yang
    ├─artifacts
    ├─cli
    │  └─src
    │      └─main
    │          ├─java
    │          │  └─org
    │          │      └─opendaylight
    │          │          └─example
    │          │              └─cli
    │          │                  ├─api
    │          │                  ├─commands
    │          │                  └─impl
    │          └─resources
    │              └─org
    │                  └─opendaylight
    │                      └─blueprint
    ├─features
    │  └─src
    │      └─main
    │          └─features
    ├─impl
    │  └─src
    │      ├─main
    │      │  ├─java
    │      │  │  └─org
    │      │  │      └─opendaylight
    │      │  │          └─example
    │      │  │              └─impl
    │      │  └─resources
    │      │      └─org
    │      │          └─opendaylight
    │      │              └─blueprint
    │      └─test
    │          └─java
    ├─it
    │  └─src
    │      └─test
    │          └─java
    │              └─org
    │                  └─opendaylight
    │                      └─example
    │                          └─it
    ├─karaf
    └─src
        ├─main
        │  └─resources
        └─site

 2. 执行 mvn clean install -Dmaven.test.failure.ignore=true,成功后的信息如下:

  3. 进入到 karaf.bat 目录,启动karaf

D:\\CODE\\odlexample\\example1\\example\\karaf\\target\\assembly\\bin>karaf
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=256M; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
Apache Karaf starting up. Press Enter to open the shell now...
100% [========================================================================]

Karaf started in 32s. Bundle stats: 294 active, 294 total

    ________                       ________                .__  .__       .__     __
    \\_____  \\ ______   ____   ____ \\______ \\ _____  ___.__.|  | |__| ____ |  |___/  |_
     /   |   \\\\____ \\_/ __ \\ /    \\ |    |  \\\\__  \\<   |  ||  | |  |/ ___\\|  |  \\   __\\
    /    |    \\  |_> >  ___/|   |  \\|    `   \\/ __ \\\\___  ||  |_|  / /_/  >   Y  \\  |
    \\_______  /   __/ \\___  >___|  /_______  (____  / ____||____/__\\___  /|___|  /__|
            \\/|__|        \\/     \\/        \\/     \\/\\/            /_____/      \\/


Hit \'<tab>\' for a list of available commands
and \'[cmd] --help\' for help on a specific command.
Hit \'<ctrl-d>\' or type \'system:shutdown\' or \'logout\' to shutdown OpenDaylight.

opendaylight-user@root>

 

查看Example是否加载成功:

opendaylight-user@root>log:display | grep Example
2017-07-25 17:54:25,488 | INFO  | rint Extender: 1 | ExampleProvider                  | 208 - org.opendaylight.example.impl - 0.1.0.SNAPSHOT | ExampleProvider Session Initiated
opendaylight-user@root>

 关闭OpenDaylight:

opendaylight-user@root>shutdown -f
opendaylight-user@root>

三、问题记录

[INFO] --- maven-antrun-plugin:1.8:run (move-autowire-test) @ example-features ---
[INFO] Executing tasks

main:
     [echo] Moving autowire.xml to org/opendaylight/blueprint
[INFO] Executed tasks
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ example-features ---
[INFO] Surefire report directory: D:\\CODE\\odlexample\\example1\\example\\features\\target\\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.opendaylight.odlparent.featuretest.SingleFeatureTest

 surefire-reports对应的报错信息为:

  <testcase name="installFeature" classname="installFeature(org.opendaylight.odlparent.featuretest.SingleFeatureTest)[repoUrl: file:/D:/CODE/odlexample/example1/example/features/target/classes/features.xml, Feature: odl-example-api 0.1.0-SNAPSHOT]" time="185.064">
    <error message="ffaf2fde-a115-4b78-a169-524b099119b6" type="java.rmi.NotBoundException">java.rmi.NotBoundException: ffaf2fde-a115-4b78-a169-524b099119b6
    at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:209)
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:450)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at org.ops4j.pax.exam.rbc.client.intern.RemoteBundleContextClientImpl.getRemoteBundleContext(RemoteBundleContextClientImpl.java:242)
    at org.ops4j.pax.exam.rbc.client.intern.RemoteBundleContextClientImpl.waitForState(RemoteBundleContextClientImpl.java:211)
    at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.waitForState(KarafTestContainer.java:607)
    at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.startKaraf(KarafTestContainer.java:241)
    at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.start(KarafTestContainer.java:181)
    at org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactor.invoke(AllConfinedStagedReactor.java:79)
    at org.ops4j.pax.exam.junit.impl.ProbeRunner$2.evaluate(ProbeRunner.java:267)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.ops4j.pax.exam.junit.impl.ProbeRunner.run(ProbeRunner.java:98)
    at org.ops4j.pax.exam.junit.PaxExam.run(PaxExam.java:93)
    at org.opendaylight.odlparent.featuretest.PerFeatureRunner.run(PerFeatureRunner.java:72)
    at org.opendaylight.odlparent.featuretest.PerRepoTestRunner.runChild(PerRepoTestRunner.java:143)
    at org.opendaylight.odlparent.featuretest.PerRepoTestRunner.runChild(PerRepoTestRunner.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
</error>
    <system-out><![CDATA[[sys.out] About to run test: org.opendaylight.odlparent.featuretest.SingleFeatureTest[repoUrl: file:/D:/CODE/odlexample/example1/example/features/target/classes/features.xml, Feature: odl-example-api 0.1.0-SNAPSHOT]
]]></system-out>
    <system-err><![CDATA[SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/repository/org/apache/karaf/org.apache.karaf.client/3.0.8/org.apache.karaf.client-3.0.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/repository/org/ops4j/pax/logging/pax-logging-api/1.8.4/pax-logging-api-1.8.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/repository/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
2923 [main] ERROR org.opendaylight.odlparent.featuretest.PerRepoTestRunner - getClass().getClassLoader().getResource("feature.xml") returned null
3094 [main] ERROR org.opendaylight.odlparent.featuretest.PerRepoTestRunner - getClass().getClassLoader().getResource("feature.xml") returned null
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: -3
]]></system-err>

原有的mvn命令为:mvn clean install --Dmaven.test.skip=true,报上面的错误后,将mvn命令调整为:mvn clean install -Dmaven.test.failure.ignore=true,surefire-reports仍有报错信息(消耗一定的时间),但最终会跳过去。

附:

-DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下。

-Dmaven.test.skip=true,不执行测试用例,也不编译测试用例类。

-Dmaven.test.failure.ignore=true,即使测试出现失败用例,仍然希望能继续构建项目

参考链接:http://www.cnblogs.com/pixy/p/4718176.html

以上是关于从零开始学OpenDaylight之使用Archetype构建项目的主要内容,如果未能解决你的问题,请参考以下文章

从零开始学OpenDaylight之六:YANG

从零开始学OpenDaylight之四:Maven工具

从零开始学多线程之构建快

python之感知器-从零开始学深度学习

《从零开始学Swift》学习笔记(Day 57)——Swift编码规范之注释规范:

从零开始学 Web 之 DOM事件冒泡