github下载源码,
版本18.0.0
java和maven的版本如下
E:\keycloak-18.0.0>java -version
java version "21.0.1" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)
E:\keycloak-18.0.0>mvn -version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
E:\keycloak-18.0.0>
修改maven的镜像仓库为官方指定的,否则会报错
<mirrors>
<mirror>
<id>jboss-public-repository-group-https</id>
<mirrorOf>jboss-public-repository-group</mirrorOf>
<name>Jboss public https</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</mirror>
</mirrors>
然后先install一遍下载各种依赖
mvn -Dmaven.test.skip clean install
可能会报错,没什么问题,只要能下载大部分的依赖就行
然后用IDEA打开源码
找到类
org.keycloak.testsuite.KeycloakServer
启动
可以发现默认使用了h2做了DB。
直接DEBUG启动,找到决定使用什么DB的地方
修改keycloak-server.json
"connectionsJpa": {
"default": {
"url": "${keycloak.connectionsJpa.url:jdbc:mysql://localhost:3306/keycloakTest?useSSL=false&serverTimezone=GMT%2B8&characterEncoding=UTF-8}",
"driver": "${keycloak.connectionsJpa.driver:com.mysql.jdbc.Driver}",
"driverDialect": "${keycloak.connectionsJpa.driverDialect:org.hibernate.dialect.MySQL5InnoDBDialect}",
"user": "${keycloak.connectionsJpa.user:root}",
"password": "${keycloak.connectionsJpa.password:123456}",
"showSql": "${keycloak.connectionsJpa.showSql:}",
"formatSql": "${keycloak.connectionsJpa.formatSql:}",
"globalStatsInterval": "${keycloak.connectionsJpa.globalStatsInterval:}"
}
},
再次启动org.keycloak.testsuite.KeycloakServer
自动创建了一个超管账户admin admin
DB里自动初始化了几十个表
登录