无法在AUTOSERVER模式下从命令行运行org.h2.tools.Script

时间:2016-07-13 16:21:29

标签: h2 tomee

我在自动服务器模式下运行H2,以便多个进程可以访问它。但是当TOMEE已经使用它时,我无法从命令行运行org.h2.tools.Script。如果我关闭TOMEE,org.h2.tools.Script工作正常。

这是我正在使用的通讯
java -cp h2-1.4.188.jar org.h2.tools.Script -url' jdbc:h2:〜/ test; FILE_LOCK = FILE; AUTO_SERVER = TRUE' -user sa -password sa -script test.sql

我在Tomcat启动时发出命令时遇到的异常

  Exception in thread "main" org.h2.jdbc.JdbcSQLException: IO Exception: "java.io.FileNotFoundException: /var/lib/test.sql (Permission denied)"; SQL statement:
SCRIPT  TO '/var/lib/test.sql'  [90028-188]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
        at org.h2.message.DbException.get(DbException.java:168)
        at org.h2.message.DbException.convertIOException(DbException.java:328)
        at org.h2.command.dml.ScriptBase.openOutput(ScriptBase.java:146)
        at org.h2.command.dml.ScriptCommand.query(ScriptCommand.java:159)
        at org.h2.command.CommandContainer.query(CommandContainer.java:90)
        at org.h2.command.Command.executeQuery(Command.java:197)
        at org.h2.server.TcpServerThread.process(TcpServerThread.java:320)
        at org.h2.server.TcpServerThread.run(TcpServerThread.java:159)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: /var/lib/test.sql (Permission denied)
        at java.io.FileOutputStream.open0(Native Method)
        at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
        at org.h2.store.fs.FilePathDisk.newOutputStream(FilePathDisk.java:290)
        at org.h2.store.fs.FileUtils.newOutputStream(FileUtils.java:233)
        at org.h2.command.dml.ScriptBase.openOutput(ScriptBase.java:144)
        ... 6 more

        at org.h2.engine.SessionRemote.done(SessionRemote.java:624)
        at org.h2.command.CommandRemote.executeQuery(CommandRemote.java:158)
        at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:179)
        at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:158)
        at org.h2.tools.Script.process(Script.java:141)
        at org.h2.tools.Script.process(Script.java:120)
        at org.h2.tools.Script.runTool(Script.java:101)
        at org.h2.tools.Script.main(Script.java:46)

我不确定为什么会看到FileNotFoundException。请记住,当TOMEE没有运行时,这就消失了。

有什么想法吗?我在一个码头工人的容器里。我确保URL在TOMEE和Script之间匹配。

1 个答案:

答案 0 :(得分:0)

我发现了为什么会这样。 TOMEE流程正在运行&#39; test&#39; Script命令以root身份运行时的用户。从TOMEE开始,首先访问H2 DB,然后测试&#39;用户应该有权写入/ var / lib /。但/ var / lib文件夹具有root用户的权限,因此测试用户无法写入。