ThingsBoard 3.0 本地环境搭建和源码编译安装

本章将介绍ThingsBoard的本地环境搭建,以及源码的编译安装。本机环境:jdk1.8、postgresql-12.2-2-windows-x64、maven 3.6.2、node v12.18.2、idea 2020.1、redis 3.2。

环境安装

开发环境要求:

  1. Jdk 1.8 版本 ;
  2. Postgresql 9 以上;
  3. Maven 3.6 以上;
  4. Git 工具;
  5. Idea 开发工具;
  6. Redis;
  7. Node.js,npm;

上述条件满足后,接下来是通过 Git 拉取代码。

thingsboard 安装步骤

温馨提醒:由于网络原因等因素,若安装过程中失败,建议先清空maven本地仓库的jar以及ui-ngx工程下的node_modules目录。然后再执行下面操作。

获取 thingsboard 代码

在本地创建代码存放位置的文件目录,然后进入当前目录点击鼠标右键,选择 Git Bash Here,输入 git 命令克隆源代码。本章节以3.0版本为例。

git clone -b release-3.0 https://github.com/thingsboard/thingsboard.git

maven 镜像源配置

由于默认仓库地址的下载速度很慢,因此使用阿里云的镜像会节省很多时间。maven conf目录下的settings.xml配置如下:

<mirrors>
    <mirror>  
        <id>nexus-aliyun</id>  
        <mirrorOf>central</mirrorOf>    
        <name>Nexus aliyun</name>  
        <url>https://maven.aliyun.com/repository/public</url>  
    </mirror> 
 </mirrors>

npm 镜像源配置

npm config set registry https://registry.npm.taobao.org       #使用淘宝镜像
npm config get registry       #查询当前镜像

IDEA 导入 thingsboard

导入后,先使用maven工具清理项目编译文件。

image

导入IDEA后,需要改下pom文件里面的node和npm版本与你本地的一致。如图:

image

注意!!!!thingsboard 3.1版本包管理换成了yarn,因此要看清pom文件的xml标签,yarnVersion对应yarn的版本。

image

改完之后可以去掉license检查步骤,节省编译时间。

image

开始编译

在 IDEA 控制台(左下方)Terminal 输入以下命令进行编译:

mvn clean install -DskipTests
image

等一段时间后,看到下面这张图就算编译成功,如果没有编译成功请按照本教程最后的常见问题进行排查。

image

常见问题

JavaScript Executor 编译失败

[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.0:npm (npm install) on project js-executor: Failed to run task: 'npm install' failed. (error code 2) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :js-executor

原因:本地缓存缺少 fetched-v10.15.3-linux-x64 和 fetched-v10.15.3-win-x64 或 fetched-v10.17.10-linux-x64 和 fetched-v10.17.10-win-x64 这两个文件。
解决办法:

  1. 下载这两个文件到本地,下载后记得重命名,下载地址:Github地址
    如果github上的这几个文件下载很慢,可以直接使用csdn下载,链接如下:
    fetched-v10.17.0-win-x64
    fetched-v10.17.0-linux-x64
    fetched-v10.15.3-win-x64
    fetched-v10.15.3-linux-x64
  2. 如何你的csdn没有积分,可直接在物联工坊免费下载,链接如下:
    fetched-v10.17.0-win-x64
    fetched-v10.17.0-linux-x64
    fetched-v10.15.3-win-x64
    fetched-v10.15.3-linux-x64
  3. 下载完成后,放到C盘用户下的.pkg目录,如图:
image

npm:npm ERR! path git

[ERROR] npm ERR! code ENOGIT

[ERROR] npm ERR! No git binary found in $PATH
[ERROR] npm ERR!
[ERROR] npm ERR! Failed using git.
[ERROR] npm ERR! Please check if you have git installed and in your PATH.
[ERROR]
[ERROR] npm ERR! A complete log of this run can be found in:

[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.0:npm
(npm install) on project ui: Failed to run task: 'npm install' failed. (error c
ode 1) -> [Help 1]

原因:没有安装git或者是没有配置git的环境变量

Build 找不到类或符号

编译前需要安装proto和lombok插件,可直接在插件市场安装,如图:

image

安装完成后重启idea进行编译。如果是2020版本的idea,可能还会报找不到符号之类的错误,这个时候需要清理下缓存重启idea:

image

还报这个错误的话,需要重置下idea的配置:

image

node 不是有效的 Win32 应用程序

Failed to run task: 'npm install' failed. java.io.IOException: Cannot run program "E:\git\thingsboard\ui-ngx\target\node\node.exe" (indirectory "E:\git\thingsboard\ui-ngx"): CreateProcess error=193, %1 不是有效的 Win32 应用程序。 -> [Help 1]

解决:将已经安装的C:\Program Files\nodejs\node.exe(node的安装路径)复制到maven本地仓库F:\share\local_repo\com\github\eirslett\node\12.18.2(本地仓库的node目录,版本号自行对应,名称自行修改)

[ERROR] PROTOC FAILED

[ERROR] PROTOC FAILED:...\thingsboard\common\message\src\main\proto\tbmsg.proto: No such file or directory

原因:thingsboard 项目地址不支持中文。
解决:将项目转移到全英文路径

结语

自己在编译Thingsboard 3.0也遇到了很多麻烦,在此总结一下,也希望可以帮助到更多的小伙伴,避免和我踩一样的坑。

本文转载自物联工坊,原文地址:物联工坊

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • (历经200多次修改 ,只为更好的内容) DCjanus[https://www.zhihu.com/people...
    科幻经典阅读 7,181评论 1 0
  • 前述. 最近在学习前端框架Vue,也是从零开始学习的小白,主要参考学习资料:Vue官网、菜鸟教程现记录学习过程中的...
    缘宸_阅读 242评论 0 0
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 7,594评论 16 22
  • 创业是很多人的梦想,多少人为了理想和不甘选择了创业来实现自我价值,我就是其中一个。 创业后,我由女人变成了超人,什...
    亦宝宝阅读 1,895评论 4 1
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    迷月闪星情阅读 10,620评论 0 11