thingsboard入门教程:本地环境搭建和源码编译安装,献给thingsboard编译失败的同学,教程不断优化 · 物联网平台-威尼斯人最新

45 条评论 , 0 次修正,42658 次阅读, last modified at march 16, 2022

关注 “云腾五洲” 公众号:只为更好的服务

thingsboard 技术交流 qq 群:69998183

如果安装有其他问题,可以优先查看本文后面的各种编译问题澳门人威尼斯3966的解决方案,如果还不行可以到交流群求助:121202538(满)、6090590

环境安装

开发环境要求: jdk 1.8 版本 postgresql 9 以上 node.js npm maven 3.6 以上 git 工具 idea 开发工具 redis

jdk

下载安装

jdk 官方下载地址:

jdk 版本选择 jdk8,我本地环境是 windos10 64 位,所以选择 jdk-8u221-windows-x64.exe

下载好了之后直接默认安装就行

配置环境变量

步骤 1: 在 java_home 中增加 jdk 的安装地址:c:\program files\java\jdk1.8.0_221

步骤 2: 在 classpath 中增加 jdk 的安装地址中的文件:.;%java_home%\lib;%java_home%\lib\dt.jar;%java_home%\lib\tools.jar

步骤 3: 在 path 中增加 jdk 的地址:%java_home%\bin;%java_home%\jre\bin;

步骤 4 输入以下命令

java -version

如果能出现以下的提示信息,就算安装成功了

安装 idea

参考:idea 安装教程

安装 maven

步骤 1:下载 maven,进入地址:

步骤 2:下载到本地

步骤 3:配置环境变量 增加 maven_home,即 maven 的地址:d:\tb\apache-maven-3.6.1-bin,请注意,如果直接解压,有可能会有两个 apache-maven-3.6.1-bin

maven_opts,参数是 -xms128m -xmx1024m

修改 path,增加 maven 的地址%maven_home%\bin;

测试 maven 安装,打开命令行工具。使用命令 mvn -v,如果能出现以下提示,即安装成功

nodejs 安装

步骤 1:下载 nodejs 安装包,nodejs 澳门人威尼斯3966官网地址:

步骤 2:安装完成后,使用命令查看 nodejs 是否已经安装完成,能出现以下提示说明已经安装成功

安装 git

步骤 1:下载 git 安装包,git 澳门人威尼斯3966官网地址是:

步骤 2:安装完成后,使用命令行测试 git

安装 npm 全局依赖

步骤 1:使用管理员 cmd 命令行,执行下面命令

#npm 环境读取环境变量包
npm install -g cross-env
#webpack打包工具
npm install -g webpack

安装 redis

redis 安装参考:https://www.iotschool.com/wiki/redis

环境安装到此结束,接下来是通过 git 拉取代码。

克隆 thingsboard 代码

确定代码存放位置

在本地创建代码存放位置的文件目录,然后进入当前目录点击鼠标右键,选择 git bash here

输入 git 命令克隆源代码

git clone https://github.com/thingsboard/thingsboard.git

耐心等待一段时间后,看到以下界面就算下载成功

切换 git 分支

默认下载的代码是 master 主分支的,我们开发需要切换到最新版本的分支。

查看项目源码的所有分支,下载源码后,需要进入到 thingsboard 文件夹

发现最新发布的版本是 2.4,所以我这里选择 2.4,当然你可以根据自己的情况进行分支选择

输入命令以下,即可切换至 2.4 的分支

git checkout release-2.4

看到下图这样,即切换成成功

准备工作

外网连接

因为 tb 在编译过程中需要依赖很多国外的包,那么需要外网才能连接,有连接外网支持,可以到社区求助:https://www.iotschool.com/topics/node8

设置 maven 为淘宝镜像

工程是基于 maven 管理,直接通过 idea open,之后会自动下载各种依赖包。依赖包的默认存储地址为:c:\users\用户名.m2\repository,内容如下:

$tree ~/.m2 -l 2
/home/jay/.m2
└── repository
    ├── antlr
    ├── aopalliance
    ├── asm
    ├── backport-util-concurrent
    ├── ch
    ...

一般情况下,使用官方镜像更新依赖包,网速不稳定,可将 maven 镜像源设置为淘宝的,在 maven 安装包目录下找到 settings.xml 设置
大概位置截图:

把 settings.xml 里面内容设置成以下:


  
       
       aliyun_nexus
       *,!maven_nexus_201 
       http://maven.aliyun.com/nexus/content/groups/public/
   

不会设置的,可以参考这个文件:

thingsboard qq 群也有这个资源:121202538

设置 npm 为淘宝镜像

同上,网速不好 npm 过程中也会下载失败,这是导致很多同学 thingsboard 编译失败的主要原因,所以我们在进行编译之前,也将 npm 替换为淘宝镜像:

npm config set registry https://registry.npm.taobao.org    #使用淘宝镜像
npm config get registry                                                             #查询当前镜像
npm config rm registry                                                              #删除自定义镜像,使用官方镜像
npm info express

设置 idea 管理员启动

我本地开发环境编译项目使用 idea 工具进行编译,所以需要设置管理员启动,这样才有所有的权限执行编译命令。 步骤 1:点击 idea 图标右键,选择属性。

步骤 2:点击兼容性 - 更改所有用户设置 - 以管理员身份运行此程序

开始编译

编译项目跟网速有关,最好连接上外网进行编译,一般 5~30 分钟都有可能,超过 30 分钟要检查你的网络。

清理项目编译文件

使用 idea maven 工具进行清理

输入编译命令开始编译

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

mvn clean install -dskiptests

等一段时间后,看到下面这张图就算编译成功,如果没有编译成功请按照本教程最后的常见问题进行排查,一般都是网络问题。如果还有问题,请到社区thingsboard 专题中提问。

常见问题

本教程只会罗列威尼斯人最新-澳门人威尼斯3966小编在 thingsboard 编译过程中遇到的问题,如果有其他问题,请到社区thingsboard 专题中提问,会有专家为你解答。

缓存导致编译失败

每次编译失败进行二次编译时,要清理缓存,并杀死遗留进程 步骤 1:执行下面命令,杀死遗留进程

taskkill /f /im java.exe

步骤 2:使用 idea maven 工具进行清理

温馨提示:要进行二次编译前,最好重启一次电脑!

server ui 编译失败

[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 code 1) -> [help 1]

如果遇到这个问题,可从以下几个原因进行分析:

原因 1:node、npm 版本号问题

本地环境安装的 node、npm 版本号与源码中 pom.xml 文件配置的版本号不一致。

澳门人威尼斯3966的解决方案: 步骤 1:使用 node -v、npm -v 查看安装的 node 和 npm 版本号

步骤 2:修改源码中 pom.xml 文件中的版本号


   v12.13.1
   6.12.1

需要修改的文件有三处,位置如下:

原因 2:node-sass 下载失败

编译 server ui 时,会下载 node-sass 依赖,如果因为网络原因没有下载成功,也会编译失败。如果你是按照本本教材一步一步来的,应该不会有问题,上面准备工作中,将 npm 镜像源切换为淘宝,那么下载会很快的。

[info] downloading binary from https://github.com/sass/node-sass/releases/download/v4.12.0/win32-x64-72_binding.node
[error] cannot download "https://github.com/sass/node-sass/releases/download/v4.12.0/win32-x64-72_binding.node":
[error]
[error] esockettimedout
[error]
[error] hint: if github.com is not accessible in your location
[error]       try setting a proxy via http_proxy, e.g.
[error]
[error]       export http_proxy=http://example.com:1234
[error]
[error] or configure npm proxy via
[error]
[error]       npm config set proxy http://example.com:8080
[info]
[info] > node-sass@4.12.0 postinstall f:\workspace\thingsboard\thingsboard\ui\node_modules\node-sass
[info] > node scripts/build.js
[info]

澳门人威尼斯3966的解决方案:切换镜像源为淘宝

澳门人威尼斯3966的解决方案:重启电脑,清理缓存

原因 3:thingsboard 3.0 版本编译遇到的问题

亲测:2.4 版本也可以通过这种方式来解决

failed to execute goal com.github.eirslett:frontend-maven-plugin:1.7.5:npm (npm install) on project ui-ngx: failed to run task: 'npm install' failed. org.apache.commons.exec.executeexception: process exited with an error: -4048 (exit value: -4048) -> [help 1]

澳门人威尼斯3966的解决方案:https://www.iotschool.com/topics/84

原因 4:二次编译导致残留进程

报错:

[error] failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project ui: failed to clean project: failed to delete f:\workspace\thingsboard\thingsboard\ui\target\node\node.exe -> [help 1]

server tool 编译失败

[error] failed to execute goal on project tools: could not resolve dependencies for project org.thingsboard:tools:jar:2.4.3: failed to collect dependencies at org.eclipse.paho:org.eclipse.paho.client.mqttv3:jar:1.1.0: failed to read artifact descriptor for org.eclipse.paho:org.eclipse.paho.clien
t.mqttv3:jar:1.1.0: could not transfer artifact org.eclipse.paho:org.eclipse.paho.client.mqttv3:pom:1.1.0 from/to aliyun_nexus (http://maven.aliyun.com/nexus/content/groups/public/): failed to transfer file http://maven.aliyun.com/nexus/content/groups/public/org/eclipse/paho/org.eclipse.paho.cli
ent.mqttv3/1.1.0/org.eclipse.paho.client.mqttv3-1.1.0.pom with status code 502 -> [help 1]

一般由于网络原因,iotschool 小编至少编译了 3 次才成功,每次编译都重启电脑,并清理环境。

澳门人威尼斯3966的解决方案:如果使用的是 mvn clean install -dskiptests 命令进行编译,那么就多尝试几次,每次编译前,要清理环境。

参考:

javascript executor 编译失败

javascript executor microservice 编译失败

[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  -rf :js-executor

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

澳门人威尼斯3966的解决方案: 步骤 1:下载这两个文件到本地,下载后记得重命名,下载地址:

步骤 2: 将下载的两个文件放到:放到:c:\users\你的用户名 \ .pkg-cache\v2.6。并将名字分别修改为:fetched-v10.15.3-linux-x64 和 fetched-v10.15.3-win-x64

参考:

license 检查不通过

[error] failed to execute goal com.mycila:license-maven-plugin:3.0:check (default) on project thingsboard: some files do not have the expected license header -> [help 1]

澳门人威尼斯3966的解决方案:在根目录 pom.xml 中屏蔽 license-maven-plugin

搜索 license-maven-plugin,将整个 plugin 都注释掉

web ui 编译失败

web ui 编译失败请参考server ui 编译失败第一个原因

maven:could not resolve dependencies for project org.thingsboard:application:

错误信息

[error] failed to execute goal on project application: could not resolve dependencies for project org.thingsboard:application:jar:2.4.1: the following artifacts could not be resolved: org.thingsboard.rule-engine:rule-engine-components:jar:2.4.1, org.thingsboard:dao:jar:2.4.1: could not find artifact org.thingsboard.rule-engine:rule-engine-components:jar:2.4.1 in jenkins (http://repo.jenkins-ci.org/releases) -> [help 1]

澳门人威尼斯3966的解决方案:根目录下去 maven 编译,不要在每个单独编译,否则不能自动解决依赖,如果你已经在子模块进行了编译,请回到根目录先 clean 一下,再重新编译。

maven:failed to delete tb-http-transport.rpm

错误信息:

[error] failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project http: failed to clean project: failed to delete d:\my_project\thingsboard\transport\http\target\tb-http-transport.rpm -> [help 1]

澳门人威尼斯3966的解决方案:第一次编译失败,再次编译可能会提示该错误,可以手动到报错路径删除,如果提示文件正在使用,需要在任务管理器杀死 java 进程后再手动删除。

npm:npm:cb() never called!

错误信息:

npm err! cb() never called!
npm err! this is an error with npm itself. please report this error at:
npm err!     
npm err! a complete log of this run can be found in:
npm err!     c:\users\yuren\appdata\roaming\npm-cache\_logs\2019-11-06t10_55_28_258z-debug.log

澳门人威尼斯3966的解决方案: 尝试 npm cache clean --force 后再次 npm install 无果; 尝试更换淘宝镜像源后再次 npm install 无果; 怀疑有些包下载需要翻墙,全局代理翻墙后问题依然存在; 参考网上关闭所有代理后问题依然存在; 通过 log 日志分析最后一个解包报错的地方,屏蔽需要的 material-design-icons,新 modules rxjs 仍然报错;

extract material-design-icons@3.0.1 extracted to node_modules\.staging\material-design-icons-61b4d55e (72881ms)
extract rxjs@6.5.2 extracted to node_modules\.staging\rxjs-e901ba4c (24280ms)

参考 npm err cb() never called 执行

npm install --no-package-lock

之后提示 npm err! path git,添加 git 到环境变量后正常。

npm:npm err! path git

错误信息

npm err! path git
npm err! code enoent
npm err! errno enoent
npm err! syscall spawn git
npm err! enoent error while executing:
npm err! enoent undefined ls-remote -h -t git://github.com/fabiobiondi/angular-

澳门人威尼斯3966的解决方案:添加 git 到环境变量。

no compiler is provided in this environment

错误信息:

[error] failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
1:compile (default-compile) on project netty-mqtt: compilation failure
[error] no compiler is provided in this environment. perhaps you are running on
a jre rather than a jdk?

需要在环境变量中设置 java,包含%java_home%bin;%java_home%lib;

更多问题,请到社区解决:https://www.iotschool.com/topics/node8

网站地图