前言
本文以release-3.6为基础,源码编译后启动jar包工程。
1.前置条件
1. java,ThingsBoard从3.2.2之后将JDK更新到11版本
2. Maven镜像配置
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
3. git安装,安装历史悠久,不再叙述
4. 安装node.js,安装node会自动安装npm,
参考地址:https://blog.csdn.net/m0_61961937/article/details/127322347
#使用淘宝镜像
npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
#查询当前镜像
npm config get registry
5. 安装yarn
npm安装yarn:npm install -g yarn
#设置淘宝镜像:
yarn config set registry https://registry.npm.taobao.org -g
yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g
#使用yarn config list查看,发现的新版的yarn是严格检查ssl的,关闭严格检查SSL设置
yarn config set strict-ssl false
6. 安装PostgreSQL,使用PostgreSQL 12.X及以上版本
#参考地址:https://www.cnblogs.com/wenhuang/p/10706931.html
2.获取源码,修改配置、代码
1. 拉取源码:git clone https://gitee.com/mirrors/ThingsBoard.git
2. 切换分支:git checkout release-3.6
3. 注释、修改配置文件
3.1 根目录pom.xml文件找到license-maven-plugin,并将整个plugin注释掉
3.2 application模块中的thingsboard.yml文件修改数据库相关信息
3.3 ui-ngx模块中的pom.xml文件修改node/yarn版本号
3.4 msa/js-executor模块中的pom.xml文件修改node/yarn版本号
4. 启动时异常处理:Error creating bean with name 'defaultTbMailConfigTemplateService': Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [templates/mail_config_templates.json] cannot be resolved to absolute file path because it does not reside in the file system:
解决方式:
1. 修改类org.thingsboard.server.service.mail.DefaultTbMailConfigTemplateService.java文件获取模板文件方法
原方法:mailConfigTemplates = JacksonUtil.toJsonNode(new ClassPathResource("/templates/mail_config_templates.json").getFile());
调整为:
ApplicationHome applicationHome = new ApplicationHome(DefaultTbMailConfigTemplateService.class);
//项目打包成jar包所在的根路径
String rootPath = applicationHome.getSource().getParentFile().toString();
String configFilePath = rootPath + "/templates/mail_config_templates.json";
File configFile = new File(configFilePath);
mailConfigTemplates = JacksonUtil.toJsonNode(configFile);
2. 复制ThingsBoard\application\src\main\resources下的templates目录至项目运行jar包所在的根路径
5. 新增租户时异常处理Please use either root project directory, application module directory or specify valid "install.data_dir" ENV variable to avoid automatic data directory lookup!
解决方式:在项目运行jar包所在的根路径,新建文件夹目录:application\src\main,将ThingsBoard\application\target或者ThingsBoard\application\src\main下的data目录复制至该目录中
3.mvn命令编译
# -DskipTests 不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下,-X 显示maven允许的debug信息
mvn clean install -DskipTests -X
或
# -Dmaven.test.skip=true不执行测试用例,也不编译测试用例类
mvn clean install -Dmaven.test.skip=true
4.项目启动,登录
导入数据:PostgreSQL中新建数据库(对应application模块中的thingsboard.yml文件中的数据库相关信息),cmd进入目录\ThingsBoard\application\target\windows,执行install_dev_db.bat初始化数据
启动: cmd命令行jar包启动:java -jar *****.jar
注:nohup java -jar *****.jar & 表示不挂断运行命令,当账户退出或终端关闭时,程序仍然运行。注意,该作业的所有输出被重定向到nohup.out的文件中
或者eclipse中run application模块下的ThingsboardServerApplication.java(eclipse暂未调试成功)
登录:访问本机localhost:8080登录
默认系统账户:sysadmin@thingsboard.org,密码:sysadmin
租户管理员:tenant@thingsboard.org,密码:tenant
客户:customer@thingsboard.org,密码:customer
5.异常处理
1. 启动时异常处理:Error creating bean with name 'defaultTbMailConfigTemplateService': Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [templates/mail_config_templates.json] cannot be resolved to absolute file path because it does not reside in the file system:
解决方式:
1. 修改类org.thingsboard.server.service.mail.DefaultTbMailConfigTemplateService.java文件获取模板文件方法
原方法:mailConfigTemplates = JacksonUtil.toJsonNode(new ClassPathResource("/templates/mail_config_templates.json").getFile());
调整为:
ApplicationHome applicationHome = new ApplicationHome(DefaultTbMailConfigTemplateService.class);
//项目打包成jar包所在的根路径
String rootPath = applicationHome.getSource().getParentFile().toString();
String configFilePath = rootPath + "/templates/mail_config_templates.json";
File configFile = new File(configFilePath);
mailConfigTemplates = JacksonUtil.toJsonNode(configFile);
2. 复制ThingsBoard\application\src\main\resources下的templates目录至项目运行jar包所在的根路径
2. 新增租户时异常处理Please use either root project directory, application module directory or specify valid "install.data_dir" ENV variable to avoid automatic data directory lookup!
解决方式:在项目运行jar包所在的根路径,新建文件夹目录:application\src\main,将ThingsBoard\application\target或者ThingsBoard\application\src\main下的data目录复制至该目录中
3. 其他各类错误检查项
3.1 ThingsBoard从3.2.2之后将JDK更新到11版本
3.2 application模块中的thingsboard.yml文件数据库相关信息是否正确
3.3 ui-ngx、msa/js-executor模块中的pom.xml文件配置的node/yarn版本号是否与本机一致
3.4 maven、node、yarn镜像参考本文开头前置条件中检查
6.参考地址
ThingsBoard官方介绍文档:http://www.ithingsboard.com/docs/user-guide/contribution/yuanmayunxing3.3.0/
ThingsBoard开发环境搭建技巧:https://www.bilibili.com/video/BV1RQ4y167nA?p=2&vd_source=99561fbd5abc1d696ca1675ccf487a39
ThingsBoard应用教程:https://www.bilibili.com/video/BV1jy4y1f7gw/?spm_id_from=333.337.search-card.all.click&vd_source=99561fbd5abc1d696ca1675ccf487a39
node.js、npm、yarn安装和基本使用:https://blog.csdn.net/m0_61961937/article/details/127322347
windows下postgreSQL安装与启动:https://www.cnblogs.com/wenhuang/p/10706931.html
Thingsboard 实体及数据存储研究:https://www.cnblogs.com/haiiiiiyun/p/12786999.html