Код: Выделить всё
BUILD.bazel
MODULE.bazel
com/test/TestMain.java
com/test/assets/
Код: Выделить всё
load("@rules_java//java:defs.bzl", "java_binary")
package(default_visibility = ["//visibility:public"])
java_binary(
name = "TestMain",
srcs = glob(["com/test/TestMain.java"]),
main_class = "com.test.TestMain",
resources = glob(["com/test/assets/*"])
)
Код: Выделить всё
bazel_dep(name = "rules_java", version = "7.11.1")
bazel_dep(name = "sqlite3", version = "3.47.2")
Код: Выделить всё
import java.io.IOException;
import java.sql.*;
public class TestMain {
public static void main(String args[]) throws IOException {
try {
Connection connection = DriverManager.getConnection("jdbc:sqlite:com/test/assets/sample.db");
Statement statement = connection.createStatement();
statement.setQueryTimeout(30);
statement.executeUpdate("drop table if exists blog_post");
statement.executeUpdate("create table blog_post(id integer, title string, content string)");
statement.executeUpdate("insert into blog_post(1, 'test','ldsjkfslkdfjl')");
statement.executeUpdate("insert into blog_post(2, 'testdd','ldsjkfslkdfjl')");
ResultSet rs = statement.executeQuery("select * from blog_post");
while(rs.next()) {
System.out.println("title = " + rs.getString("title"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Код: Выделить всё
java.sql.SQLException: No suitable driver found for jdbc:sqlite:com/test/assets/sample.db
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
Сначала я думал добавить deps в двоичный файл, но не знаю, как это сделать. ; Я попробовал;
Код: Выделить всё
deps = ["sqlite3"]
Код: Выделить всё
in deps attribute of java_binary rule //:TestMain: target '//:sqlite3' does not exist.
Код: Выделить всё
deps = ["@sqlite3"]
Я попробовал добавить имя репозитория в bazel_dep
Код: Выделить всё
bazel_dep(name = "sqlite3", version = "3.47.2",
repo_name = "com_github_xerial_sqlite_jdbc")
Код: Выделить всё
deps = ["@com_github_xerial_sqlite_jdbc//:sqlite3"]
[*]https://github.com/bazelbuild/examples /blob/main/bzlmod/01-dependent_on_bazel_module/MODULE.bazel
[*]https://github.com/bazelbuild/examples/ ... dule/BUILD
с теми же проблемами.
Подробнее здесь: https://stackoverflow.com/questions/793 ... with-bazel
Мобильная версия