运维调试记录:Opendaylight铍版本开发环境搭建流程

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

一、系统环境

  • 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>
上一篇:C#代码生成工具:文本模板初体验 使用T4批量修改实体框架(Entity Framework)的类名


下一篇:分享实录 | 阿里巴巴自研代码管理平台技术解密