運維除錯記錄:Opendaylight鈹版本開發環境搭建流程

KiteRunner24發表於2017-06-22

一、系統環境

  • Ubuntu 14.04 LTS

  • CPU:雙核

  • 記憶體:4GB

二、步驟詳解

1. 安裝JAVA開發環境

OpenDaylight requires Java 7 JDK for Lithium . For Beryllium, a Java 8 JDK may be required.

過程:

Ubuntu 14.04的軟體源中暫不支援java 8,因此,首先解決該問題:

  • 對於Oracle JDK:
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
  • 對於Open JDK:
$ sudo add-apt-repository ppa:openjdk-r/ppa
$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk
  • 檢測是否安裝成功:
zjl@zjl-uestc:~$ java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

zjl@zjl-kb310:~$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~14.04-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

2. 安裝maven 3

Ubuntu預設支援的maven版本太低,因此,這裡選擇安裝maven 3.3.9版本。

  • 清除之前安裝的maven:
$ sudo apt-get purge -y maven
  • 轉入下載目錄:
$ cd ~/Downloads
  • 下載maven-3.3.9(使用清華大學的源):
$ sudo wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
  • 解壓安裝maven-3.3.9:
$ tar -zxvf apache-maven-3.3.9-bin.tar.gz
$ sudo cp -r apache-maven-3.3.9 /usr/local
$ sudo ln -s /usr/local/apache-maven-3.3.9/bin/mvn /usr/bin/mvn
  • 配置環境變數:
$ echo "export M2_HOME=/usr/local/apache-maven-3.3.9" >> ~/.profile
$ source ~/.profile
  • 測試是否安裝成功:
zjl@zjl-kb310:/usr/local$ mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /usr/local/apache-maven-3.3.9
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.2.0-27-generic", arch: "amd64", family: "unix"
  • 可選:提高Maven可用RAM總量的方法:

一些OpenDaylight專案可能十分大,其耗費資源也會很大,因此,可以增加Maven的可用RAM。

具體方法如下:

$ echo " export MAVEN_OPTS='-Xmx1048m -XX:MaxPermSize=512m' " >> ~/.bashrc
$ source ~/.bashrc

3. 安裝Git

略。。。

4. 修改~/.m2/settings.xml

OpenDaylight maintains its own repositories outside of Maven Central, which means maven cannot resolve OpenDaylight artifacts by default. Since OpenDaylight is organized as multiple inter-dependent projects, building a particular project usually means pulling in some artifacts. In order to make this work, your maven installation needs to know the location of OpenDaylight repositories and has to taught to use them.

具體方法:

# Shortcut command for grabbing settings.xml
$ cp -n ~/.m2/settings.xml{,.orig} ; \
    wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml

~/.m2/settings.xml的內容如下:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <profiles>
    <profile>
      <id>opendaylight-release</id>
      <repositories>
        <repository>
          <id>opendaylight-mirror</id>
          <name>opendaylight-mirror</name>
          <url>https://nexus.opendaylight.org/content/repositories/public/</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>opendaylight-mirror</id>
          <name>opendaylight-mirror</name>
          <url>https://nexus.opendaylight.org/content/repositories/public/</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>

    <profile>
      <id>opendaylight-snapshots</id>
      <repositories>
        <repository>
          <id>opendaylight-snapshot</id>
          <name>opendaylight-snapshot</name>
          <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>opendaylight-snapshot</id>
          <name>opendaylight-snapshot</name>
          <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>opendaylight-release</activeProfile>
    <activeProfile>opendaylight-snapshots</activeProfile>
  </activeProfiles>
</settings>

如果你使用了代理,那麼需要配置代理,具體閱讀:Maven proxy configuration

錯誤處理:

如果遇到了如下錯誤:

[WARNING] Error initializing: org.codehaus.plexus.velocity.DefaultVelocityComponent
java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

新增下面內容到檔案~/.m2/repository/org/apache/maven/plugins/maven-archetype-plugin/{version}/maven-archetype-plugin-{version}.pom

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.6</version>
</dependency>

相關文章