java - 如何使用系统调用 Octave 中的 .jar?

标签 java octave

我正在运行 Windows 10 x64、Octave 5.1.0 x64 和最新的 JRE。我想在 Octave 中使用 tabula 的命令行版本:

system(['java -jar c:\path\to\tabula\tabula.jar -format JSON -lattice -t -u -p 1-3 "input.pdf"']);

此代码不会运行,并立即抛出错误。当我删除这些选项时,它似乎至少开始运行,但它给出了一组不同的错误。所以我认为我至少有两个问题,其中之一是我调用选项的方式。

system(['java -jar "c:\path\to\tabula\tabula.jar" "input.pdf"']);

我尝试过包含没有连字符、单连字符、双连字符的选项,并且我尝试使用单引号和双引号(使用适当的转义符)定义字符串。当命令行与 jar 和 pdf 位于同一文件夹中时,我还尝试了文件的完整路径以及文件名。

如果包含选项,我会收到以下错误:

2019-06-06 12:11:35.497:INFO::main: Logging initialized @459ms
2019-06-06 12:11:35.502:INFO:oejr.Runner:main: Runner
ERROR: Context 'file:/C:/path/to/jar/but/not.jar/itself/format' does not exist
Usage: java [-Djetty.home=dir] -jar jetty-runner.jar [--help|--version] [ server opts] [[ context opts] context ...]
Server opts:
 --version                           - display version and exit
 --log file                          - request log filename (with optional 'yyyy_mm_dd' wildcard
 --out file                          - info/warn/debug log filename (with optional 'yyyy_mm_dd' wildcard
 --host name|ip                      - interface to listen on (default is all interfaces)
 --port n                            - port to listen on (default 8080)
 --stop-port n                       - port to listen for stop command
 --stop-key n                        - security string for stop command (required if --stop-port is present)
 [--jar file]*n                      - each tuple specifies an extra jar to be added to the classloader
 [--lib dir]*n                       - each tuple specifies an extra directory of jars to be added to the classloader
 [--classes dir]*n                   - each tuple specifies an extra directory of classes to be added to the classloader
 --stats [unsecure|realm.properties] - enable stats gathering servlet context
 [--config file]*n                   - each tuple specifies the name of a jetty xml config file to apply (in the order defined)
Context opts:
 [[--path /path] context]*n          - WAR file, web app dir or context xml file, optionally with a context path
ERROR: java.lang.NullPointerException


I get the following errors if I don't include options:


2019-06-06 12:39:05.288:INFO::main: Logging initialized @474ms
2019-06-06 12:39:05.294:INFO:oejr.Runner:main: Runner
2019-06-06 12:39:05.420:INFO:oejs.Server:main: jetty-9.2.9.v20150224
2019-06-06 12:39:23.272:WARN:oeja.AnnotationConfiguration:main: ServletContainerInitializers: detected. Class hierarchy: empty
INFO: jruby 9.1.15.0 (2.3.3) 2017-12-07 929fde8 Java HotSpot(TM) 64-Bit Server VM 25.211-b12 on 1.8.0_211-b12 +jit [mswin32-x86_64]
INFO: using a shared (threadsafe!) runtime
2019-06-06 12:39:32.319:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@2ff5659e{/,file:/C:/Users/ned/AppData/Local/Temp/jetty-0.0.
0.0-8080-tabula121.jar-_-any-3946933838247600913.dir/webapp/,AVAILABLE}{file:/C:/Users/path/to/tabula/tabula121.jar}
2019-06-06 12:39:32.386:WARN:oeja.AnnotationConfiguration:main: ServletContainerInitializers: detected. Class hierarchy: empty
2019-06-06 12:39:32.450:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@77afea7d{/,file:/C:/Users/ned/AppData/Local/Temp/jetty-0.0.
0.0-8080-input.pdf-_-any-1670794067818399886.dir/webapp/,AVAILABLE}{file:/D:/path/to/input.pdf}
2019-06-06 12:39:32.451:WARN:oejsh.RequestLogHandler:main: !RequestLog
2019-06-06 12:39:32.460:WARN:oejuc.AbstractLifeCycle:main: FAILED ServerConnector@3ad847f8{HTTP/1.1}{0.0.0.0:8080}: java.net.BindException: Addre
ss already in use: bind
java.net.BindException: Address already in use: bind
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Unknown Source)
        at sun.nio.ch.Net.bind(Unknown Source)
        at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
        at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.server.Server.doStart(Server.java:366)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.runner.Runner.run(Runner.java:509)
        at org.eclipse.jetty.runner.Runner.main(Runner.java:557)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at WarMain.launchWebServer(WarMain.java:187)
        at WarMain.start(WarMain.java:345)
        at JarMain.doStart(JarMain.java:233)
        at WarMain.main(WarMain.java:367)
2019-06-06 12:39:32.461:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.server.Server@224aed64: java.net.BindException: Address alrea
dy in use: bind
java.net.BindException: Address already in use: bind
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Unknown Source)
        at sun.nio.ch.Net.bind(Unknown Source)
        at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
        at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.server.Server.doStart(Server.java:366)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.runner.Runner.run(Runner.java:509)
        at org.eclipse.jetty.runner.Runner.main(Runner.java:557)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at WarMain.launchWebServer(WarMain.java:187)
        at WarMain.start(WarMain.java:345)
        at JarMain.doStart(JarMain.java:233)
        at WarMain.main(WarMain.java:367)
java.net.BindException: Address already in use: bind
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Unknown Source)
        at sun.nio.ch.Net.bind(Unknown Source)
        at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
        at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.server.Server.doStart(Server.java:366)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.runner.Runner.run(Runner.java:509)
        at org.eclipse.jetty.runner.Runner.main(Runner.java:557)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at WarMain.launchWebServer(WarMain.java:187)
        at WarMain.start(WarMain.java:345)
        at JarMain.doStart(JarMain.java:233)
        at WarMain.main(WarMain.java:367)
Usage: java [-Djetty.home=dir] -jar jetty-runner.jar [--help|--version] [ server opts] [[ context opts] context ...]
Server opts:
 --version                           - display version and exit
 --log file                          - request log filename (with optional 'yyyy_mm_dd' wildcard
 --out file                          - info/warn/debug log filename (with optional 'yyyy_mm_dd' wildcard
 --host name|ip                      - interface to listen on (default is all interfaces)
 --port n                            - port to listen on (default 8080)
 --stop-port n                       - port to listen for stop command
 --stop-key n                        - security string for stop command (required if --stop-port is present)
 [--jar file]*n                      - each tuple specifies an extra jar to be added to the classloader
 [--lib dir]*n                       - each tuple specifies an extra directory of jars to be added to the classloader
 [--classes dir]*n                   - each tuple specifies an extra directory of classes to be added to the classloader
 --stats [unsecure|realm.properties] - enable stats gathering servlet context
 [--config file]*n                   - each tuple specifies the name of a jetty xml config file to apply (in the order defined)
Context opts:
 [[--path /path] context]*n          - WAR file, web app dir or context xml file, optionally with a context path
ERROR: java.lang.NullPointerException


In Octave I have put the path to tabula on the javaclasspath.  When I type "javaclasspath" in Octave, I get:

    STATIC JAVA PATH
      C:\correct\path\to\tabula.jar

This is driving me crazy.  Thanks so much for your help!

最佳答案

嗯,我明白了。我缩短了 .jar 文件名,因为它真的很长。众所周知,这是不允许的。这是一个浪费时间的错误。我恢复了原始文件名,所有系统都恢复正常了。希望这篇笔记对其他人有帮助。切勿更改 .jar 文件名!感谢大家抽出时间给我。

关于java - 如何使用系统调用 Octave 中的 .jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56481480/

相关文章:

fft - 使用 GNU Octave FFT 函数

java - 如何从 JComboBox 中的选定项目中获取包含 2 个项目的数组?

java - Hibernate 延迟加载不适用于多对一映射

c++ - 在不循环的情况下写入 .oct 文件中的矩阵?

c++ - 调用一个库函数,修改它的一些行为

octave - Octave 中符号表达式的求值

java - 在共享包中使用 GWT 的 NumberFormat 类

java - 无法传递 String 和 Int var 来获取数组元素的值?

java - 在 SQL 语句中调用具有默认值的函数

python - 使用掩蔽数组的一行计算数组行的平均值