ThingsBoard 源码地址:https://github.com/thingsboard/thingsboard,从 3.7 版本之后,要求 JDK17。官方提供了源码编译的文档:Building from sources
源码编译#
下载代码:
设置当前 JDK 版本为 17 以上。这里我使用 sdkman 切换 java。
1
| sdk use java 17.0.12-tem
|
终端编译源码:
1
2
| cd thingsboard
mvn clean install -Dmaven.test.skip=true
|
如果在编译过程中提示找不到 Gradle:
1
| [ERROR] Failed to execute goal org.thingsboard:gradle-maven-plugin:1.0.12:invoke (default) on project http: org.gradle.tooling.BuildException: Could not execute build using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.3.3-bin.zip'. -> [Help 1]
|
往上查看详细异常日志:
1
2
3
4
5
6
| * What went wrong:
Could not compile build file '/Users/chensoul/Codes/github/thingsboard/packaging/java/build.gradle'.
> startup failed:
General error during conversion: Unsupported class file major version 65
java.lang.IllegalArgumentException: Unsupported class file major version 65
|
可以看到是 JDK 版本过高的原因。需要确认 JDK 版本使用 17,不能是 21。
如果 maven 下载太慢,则修改 mirrors 节点如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| <mirrors>
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:dont-match-anything-mate:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
</mirror>
<mirror>
<id>aliyun-central</id>
<name>aliyun-central</name>
<url>https://maven.aliyun.com/nexus/content/repositories/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>aliyun-jcenter</id>
<name>aliyun-jcenter</name>
<url>https://maven.aliyun.com/nexus/content/repositories/jcenter</url>
<mirrorOf>jcenter</mirrorOf>
</mirror>
</mirrors>
|
Idea 中运行#
首先 IDEA 需要安装 lombok 和 Protobuf 相关插件,有个 proto 文件生成的java代码过大(TransportProtos
),默认是不会解析的。需要编辑idea 的属性(Help -> Edit Custom Properties),加入idea.max.intellisense.filesize=3000
,将上限提高到3M。
准备 postgres 数据库,使用 docker-compose 运行:
1
2
3
4
5
6
7
8
9
| services:
postgres:
restart: always
image: "postgres:15"
ports:
- "5432:5432"
environment:
POSTGRES_DB: thingsboard
POSTGRES_PASSWORD: postgres
|
在 idea 中打开项目,然后将 dao/src/main/resources/sql 目录拷贝到 application/src/main/data 目录下。
运行 application 模块下的 ThingsboardInstallApplication 类,初始化数据库。
运行 application 模块下的 ThingsboardServerApplication 类,启动 thingsboard。
启动成功之后,在浏览器访问 http://localhost:8080/login, ThingsBoard 默认账户