网上有很多资料,每个人遇到的情况也都不一样。本人成功编译花费将近一周时间,过程整理如下:
1、下载GIT源码
- 目录右键,选择Git Bash Here
- 输入git命令克隆源代码:
git clone https://github.com/thingsboard/thingsboard.git
- 进入thingsboard文件夹:
cd thingsboard
git branch
- 列出所有版本:
git branch -a
- checkout 最新realease版本
git checkout realease-3.1
2、编译准备
- 注释插件
打开项目源码中的文件,查看其中的检查插件,打开thingsboard跟目录,pom.xml,查找license-maven-plugin,并注释掉
<!--
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>3.0</version>
<configuration>
<header>${main.dir}/license-header-template.txt</header>
<properties>
<owner>The Thingsboard Authors</owner>
</properties>
<excludes>
<exclude>**/.env</exclude>
<exclude>**/*.env</exclude>
<exclude>**/.eslintrc</exclude>
<exclude>**/.babelrc</exclude>
<exclude>**/.jshintrc</exclude>
<exclude>**/.gradle/**</exclude>
<exclude>**/nightwatch</exclude>
<exclude>**/README</exclude>
<exclude>**/LICENSE</exclude>
<exclude>**/banner.txt</exclude>
<exclude>node_modules/**</exclude>
<exclude>**/*.properties</exclude>
<exclude>src/test/resources/**</exclude>
<exclude>src/vendor/**</exclude>
<exclude>src/font/**</exclude>
<exclude>src/sh/**</exclude>
<exclude>packaging/*/scripts/control/**</exclude>
<exclude>packaging/*/scripts/windows/**</exclude>
<exclude>packaging/*/scripts/init/**</exclude>
<exclude>**/*.log</exclude>
<exclude>**/*.current</exclude>
<exclude>.instance_id</exclude>
<exclude>src/main/scripts/control/**</exclude>
<exclude>src/main/scripts/windows/**</exclude>
<exclude>src/main/resources/public/static/rulenode/**</exclude>
<exclude>**/*.proto.js</exclude>
<exclude>docker/haproxy/**</exclude>
<exclude>docker/tb-node/**</exclude>
<exclude>ui/**</exclude>
<exclude>src/browserslist</exclude>
<exclude>**/*.raw</exclude>
</excludes>
<mapping>
<proto>JAVADOC_STYLE</proto>
<cql>DOUBLEDASHES_STYLE</cql>
<scss>JAVADOC_STYLE</scss>
<jsx>SLASHSTAR_STYLE</jsx>
<tsx>SLASHSTAR_STYLE</tsx>
<conf>SCRIPT_STYLE</conf>
<gradle>JAVADOC_STYLE</gradle>
</mapping>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
-->
- 修改ui-ngx工程的pom.xml文件中node的版本。
install-node-and-npm 改为当前机器安装的版本。感觉作用不大,但是我改了。
3、 ngx-flowchart调整
因为ngx-flowchart是直接从GitHub上下载下来的,虽然编译能成功,但是会发现规则链画面打开出错。会有类似的错误提示TypeError: Class constructor X cannot be invoked without ‘new’。
修改ui-ngx的tsconfig.json,重新编译。虽然显示规则链没有问题,但是编辑规则链还是会提示错误。
"target": "es5", ===> "target": "es6",
对应方式是把ngx-flowchart的源码放到ui-ngx中,target还是原来es5,原来依赖的地方修改一下,编译后就正常了。
- 把public-api.ts改名为index.ts.
- 搜索’ngx-flowchart/dist,分别修改。
4、编译项目
- 为了编译顺利,请使用管理员运行命令,如果遇到问题,请多试几次。
mvn clean install -DskipTests
遇到问题,可以使用命令清楚,继续运行
mvn clear - java编译问题不大,关键是在ui-ngx出错。
主要解决方法时,在cmd进入thingsboard\ui-ngx目录,直接运行npm install 安装需要的依赖包。
安装过程中如有问题,基本时npm的问题。可以参考此文
本人解决主要是删除C:\Users{用户名}\AppData\Roaming下的npm。 - 编译成功会显示如下,此过程时间较长,12分钟左右。
[INFO] Reactor Summary for Thingsboard 3.1.0:
[INFO]
[INFO] Thingsboard ........................................ SUCCESS [ 0.218 s]
[INFO] Netty MQTT Client .................................. SUCCESS [ 1.937 s]
[INFO] Thingsboard Server Commons ......................... SUCCESS [ 0.018 s]
[INFO] Thingsboard Server Common Data ..................... SUCCESS [ 4.386 s]
[INFO] Thingsboard Server Common Utils .................... SUCCESS [ 0.413 s]
[INFO] Thingsboard Server Common Messages ................. SUCCESS [ 4.779 s]
[INFO] Thingsboard Actor system ........................... SUCCESS [ 0.840 s]
[INFO] Thingsboard Server Stats ........................... SUCCESS [ 0.457 s]
[INFO] Thingsboard Server Queue components ................ SUCCESS [ 8.414 s]
[INFO] Thingsboard Server Commons ......................... SUCCESS [ 0.015 s]
[INFO] Thingsboard Server Common Transport components ..... SUCCESS [ 1.352 s]
[INFO] Thingsboard MQTT Transport Common .................. SUCCESS [ 1.754 s]
[INFO] Thingsboard HTTP Transport Common .................. SUCCESS [ 0.652 s]
[INFO] Thingsboard CoAP Transport Common .................. SUCCESS [ 0.815 s]
[INFO] Thingsboard Server Common DAO API .................. SUCCESS [ 1.738 s]
[INFO] Thingsboard Extensions ............................. SUCCESS [ 0.014 s]
[INFO] Thingsboard Rule Engine API ........................ SUCCESS [ 1.316 s]
[INFO] Thingsboard Server DAO Layer ....................... SUCCESS [ 10.084 s]
[INFO] Thingsboard Rule Engine Components ................. SUCCESS [ 5.901 s]
[INFO] Thingsboard Server Transport Modules ............... SUCCESS [ 0.013 s]
[INFO] Thingsboard HTTP Transport Service ................. SUCCESS [ 16.158 s]
[INFO] Thingsboard MQTT Transport Service ................. SUCCESS [ 14.366 s]
[INFO] Thingsboard CoAP Transport Service ................. SUCCESS [ 14.163 s]
[INFO] ThingsBoard Server UI .............................. SUCCESS [02:11 min]
[INFO] Thingsboard Server Tools ........................... SUCCESS [ 1.115 s]
[INFO] Thingsboard Rest Client ............................ SUCCESS [ 0.729 s]
[INFO] ThingsBoard Server Application ..................... SUCCESS [ 45.870 s]
[INFO] ThingsBoard Microservices .......................... SUCCESS [ 0.014 s]
[INFO] ThingsBoard Docker Images .......................... SUCCESS [ 12.170 s]
[INFO] ThingsBoard JavaScript Executor Microservice ....... SUCCESS [ 59.237 s]
[INFO] ThingsBoard Web UI Microservice .................... SUCCESS [06:34 min]
[INFO] ThingsBoard Node Microservice ...................... SUCCESS [ 0.140 s]
[INFO] ThingsBoard Transport Microservices ................ SUCCESS [ 0.020 s]
[INFO] ThingsBoard MQTT Transport Microservice ............ SUCCESS [ 2.860 s]
[INFO] ThingsBoard HTTP Transport Microservice ............ SUCCESS [ 0.934 s]
[INFO] ThingsBoard COAP Transport Microservice ............ SUCCESS [ 1.596 s]
[INFO] ThingsBoard Black Box Tests ........................ SUCCESS [ 5.667 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12:26 min
[INFO] Finished at: 2020-09-02T15:15:56+08:00
[INFO] ------------------------------------------------------------------------
5、idea调试
-
使用IDEA导入Thingsboard项目,并在导入到项目后,使用菜单将Maven依赖重新引入。
导入后,application、common,dao,netty-mqtt等各工程的sourceRoot,resourceRoot都变得正常了。 -
直接使用idea的debug启动ThingsboardServerApplication即可。
注意:修改ui-ngx代码后需要执行一下编译(在ui-gnx目录下执行mvn clean install -DskipTests),直接启动才能体现。 -
常见错误:
- 内存不足,配置VM Options为-Xms256m -Xmx2048m 。
- 端口占用:默认使用的是8080,修改thingsboard.yml中配置即可。
- DB未启动:需要安装并启动postgres,具体要求可参考
- 中文语言包:下载的版本中,中文语言包不全,导致很多地方不能正确显示。对比ui-ngx\src\assets\locale\locale.constant-en_US.json修改ui-ngx\src\assets\locale\locale.constant-zh_CN.json即可。
- 编译的spring-boot.jar是用解压软件打不开。如果需要编译为能打开的,修改thingsboard跟目录下的pom.xml,找到spring-boot-maven-plugin把executable改为false即可。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>${pkg.disabled}</skip>
<mainClass>${pkg.mainClass}</mainClass>
<classifier>boot</classifier>
<layout>ZIP</layout>
<executable>false</executable>
<excludeDevtools>true</excludeDevtools>
<embeddedLaunchScriptProperties>
<confFolder>${pkg.installFolder}/conf</confFolder>
<logFolder>${pkg.unixLogFolder}</logFolder>
<logFilename>${pkg.name}.out</logFilename>
<initInfoProvides>${pkg.name}</initInfoProvides>
</embeddedLaunchScriptProperties>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>