java h2路径,基于Java的H2数据库无法在CLASSPATH中找到项目

I have a scala file has been compiled with the following command:

scalac -cp ".:*" AcmeTrigger.scala

In the directory with the .scala file I have some .jar files that contain the APIs for email and texting services that I'm using. No issues here.

The scala file essentially sends text messages and emails when someone modifies a table in a database. I start the database with the following command:

java -cp ".:*" -jar h2-1.4.182.jar

Essentially telling it to use the the .class and .jar files in directory and add them to the classpath. I've done many variations of this. Without .class, with ".:*" with the fully typed name. No matter what I do, H2 doesn't recognize the class.

So there's an operation in this database that connects the database to a class:

CREATE TRIGGER ALERT AFTER INSERT ON "event"

FOR EACH ROW CALL "AcmeTrigger"

When I run this I get an error that states it cannot find the class:

Error creating or initializing trigger "ALERT" object, class "AcmeTrigger", cause: "org.h2.message.DbException: Class ""AcmeTrigger"" not found [90086-182]"

I don't think the error is in the query syntax, but with how I'm using classpath's and was hoping someone with more Java/Scala experience could help me here. I've tried many variations of starting the .jar file but nothing seems to help.

解决方案

There's something about the default main method of the H2 jar that results in strange class loader behavior (more research needed to pinpoint what). I had the exact same experience as OP.

After copying the compiled class into your directory of choice (e.g. libs), as well as the H2 jar, run the H2 server like this:

java -cp "/libs:/libs/h2-1.4.197.jar" org.h2.tools.Server

This should result in correct resolution of the class referenced by the trigger.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值