windows下Openmetadata源码搭建
使用Openmetadata分支为main(版本为1.12.0-SNAPSHOT)。
软件清单
-
jdk21
-
mysql
-
elasticsearch
-
node>=22.17.0
-
yarn 1.22.0
-
antlr4 4.9.2
Windows上安装ANTLR4
1. 下载 ANTLR4 工具
https://www.antlr.org/download/antlr-4.9.2-complete.jar
2. 设置环境变量
将 ANTLR4 添加到系统路径:
-
将下载的
antlr-4.9.2-complete.jar文件复制到特定目录,如D:/env -
设置环境变量:
-
ANTLR4_JAR_PATH:D:/env/antlr-4.9.2-complete.jar -
将
d:/env添加到 PATH 环境变量
-
3.创建批处理脚本:
创建 antlr4.bat 文件(保存到 PATH 中的目录):
@echo off
java -jar "D:/env/antlr-4.9.2-complete.jar" %*
后端编译
修改org.openmetadata.common.utils.CommonUtil#getResourcesFromDirectory方法
public static Collection<String> getResourcesFromDirectory(File file, Pattern pattern)
throws IOException {
final Path root = Path.of(file.getPath());
try (Stream<Path> paths = Files.walk(Paths.get(file.getPath()))) {
return paths
.filter(Files::isRegularFile)
.filter(path -> {
// 适配windows 路径
String parsedPath = path.toString().replace('\\', '/');
return pattern.matcher(parsedPath).matches();
})
//.filter(path -> pattern.matcher(path.toString()).matches())
.map(
path -> {
String relativePath = root.relativize(path).toString();
LOG.debug("Adding directory file {}", relativePath);
return relativePath;
})
.collect(Collectors.toSet());
}
}
修改openmetadata-spec模块下pom.xml jsonschema2pojo-maven-plugin插件,添加以下代码(避免生成javax.annotation.Generated,造成编译异常):
<includeGeneratedAnnotation>false</includeGeneratedAnnotation>
这里只编译后端代码,排除前端2个模块
mvn clean package -DskipTests -DonlyBackend -pl !openmetadata-ui -pl !openmetadata-ui-core-components
运行openmetadata-server
IDEA配置运行程序并启动
前端编译
- 由于前端
package.json文件里面js-antlr是linux命令,所以需要修改一下源码
源码如下:
"build-check": "yarn run js-antlr && yarn run parse-schema",
"js-antlr": "PWD=$(echo $PWD) antlr4 -Dlanguage=JavaScript -o src/generated/antlr \"$PWD\"/../../../../../openmetadata-spec/src/main/antlr4/org/openmetadata/schema/*.g4",
修改如下:
"build-check": "node -e \"const os = require('os'); const cmd = os.platform() === 'win32' ? 'js-antlr-windows' : 'js-antlr-linux'; require('child_process').execSync('yarn run ' + cmd, { stdio: 'inherit' });\" && yarn run parse-schema",
"js-antlr-linux": "PWD=$(echo $PWD) antlr4 -Dlanguage=JavaScript -o src/generated/antlr \"$PWD\"/../../../../../openmetadata-spec/src/main/antlr4/org/openmetadata/schema/*.g4",
"js-antlr-windows": "powershell -Command \"antlr4 -Dlanguage=JavaScript -o src/generated/antlr (Join-Path (Get-Location) '/../../../../../openmetadata-spec/src/main/antlr4/org/openmetadata/schema/*.g4')\"",
- 修改
parseSchemas.js文件的traverseDirectory方法,解决文件路径分隔符的问题
源码如下:
async function traverseDirectory(
Directory,
playDir,
destDir,
shouldDereference = false
) {
const Files = fs.readdirSync(Directory);
for (const File of Files) {
const Absolute = path.join(Directory, File);
if (fs.statSync(Absolute).isDirectory()) {
await traverseDirectory(Absolute, playDir, destDir, shouldDereference);
} else {
// 路径分隔符的问题,是的replace的结果不正确
const name = Absolute.replace(playDir, destDir);
await parseSchema(Absolute, name, shouldDereference);
}
}
}
修改如下:
// Function to traverse directories and parse files
async function traverseDirectory(
Directory,
playDir,
destDir,
shouldDereference = false
) {
const Files = fs.readdirSync(Directory);
for (const File of Files) {
const Absolute = path.join(Directory, File);
if (fs.statSync(Absolute).isDirectory()) {
await traverseDirectory(Absolute, playDir, destDir, shouldDereference);
} else {
// 使用 path.normalize 确保路径分隔符与操作系统兼容
const normalizedAbsolute = path.normalize(Absolute);
const normalizedPlayDir = path.normalize(playDir);
const normalizedDestDir = path.normalize(destDir);
const name = normalizedAbsolute.replace(normalizedPlayDir, normalizedDestDir);
await parseSchema(Absolute, name, shouldDereference);
}
}
}
编译运行
yarn install --frozen-lockfile
yarn start
浏览器访问localhost:3000
Username:admin@open-metadata.org Password:admin
注:以上步骤省略了配置文件的配置和数据库初始化。