我正在尝试使用tlbimp-20110320.jar为com4j生成包装器。我也尝试了同样错误的2008版本。即使我尝试对抗tut中的示例,我也会遇到相同的错误。
C:\Users\matthew\Documents\NetBeansProjects\test>"C:\Program Files (x86)\Java\jr
e7\bin\java.exe" -jar tlbimp-20110320.jar -o excel -p excel "C:\Program Files (x
86)\Microsoft Office\Office14\EXCEL.EXE"
Exception in thread "main" java.lang.NoClassDefFoundError: org/kohsuke/args4j/Cm
dLineException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.kohsuke.args4j.CmdLineException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
在Iceman提供了一个指向所需库的链接后,我能够让它运行一点。但是我不得不将arg4j内容复制到tlbimp jar中,并将com4j内容复制到tlbimp jar中。现在我得到
C:\Users\matthew\Documents\NetBeansProjects\test>"C:\Program Files (x86)\Java\jr
e7\bin\java.exe" -jar tlbimp-20110320.jar -o excel -p excel "C:\Program Files (x
86)\Microsoft Office\Office14\EXCEL.EXE"
Generating definitions from Excel
A referenced type library "Office" is generated into the same package "excel"
Unable to handle the type SAVEARRAY(Variant)*
method ConnectData
interface IRtdServer
A referenced type library "VBIDE" is generated into the same package "excel"
Exception in thread "main" java.lang.NullPointerException
at com4j.tlbimp.driver.Driver$1.resolve(Driver.java:64)
at com4j.tlbimp.Generator$LibBinder.<init>(Generator.java:382)
at com4j.tlbimp.Generator.getTypeLibInfo(Generator.java:686)
at com4j.tlbimp.Generator.getTypeName(Generator.java:663)
at com4j.tlbimp.TypeBinding.bind(TypeBinding.java:173)
at com4j.tlbimp.MethodBinder.declareReturnType(MethodBinder.java:542)
at com4j.tlbimp.MethodBinder.declareWithDefaults(MethodBinder.java:399)
at com4j.tlbimp.MethodBinder.declare(MethodBinder.java:118)
at com4j.tlbimp.InvocableInterfaceGenerator.generateMethod(InvocableInte
rfaceGenerator.java:39)
at com4j.tlbimp.InterfaceGenerator.generate(InterfaceGenerator.java:94)
at com4j.tlbimp.Generator$LibBinder.generate(Generator.java:491)
at com4j.tlbimp.Generator.generate(Generator.java:112)
at com4j.tlbimp.driver.Driver.run(Driver.java:107)
at com4j.tlbimp.driver.Main.doMain(Main.java:132)
at com4j.tlbimp.driver.Main.main(Main.java:56)
答案 0 :(得分:1)
tlbimp-20110320.jar必须 args4j-2.0.1.jar 和 com4j-20110320.jar
注意: com4j-20110320.jar,有必要将名称更改为 com4j.jar
最新版本(tlbimp-2.1.jar)的tlbimp需要args4j-2.0.8.jar和com4j-2.1.jar。
在此版本中,不需要更改文件名。
答案 1 :(得分:0)
从堆栈跟踪中,您看起来缺少java类路径中的依赖jar。该程序似乎正在寻找Koshuke的args4j库 - http://args4j.kohsuke.org/。
答案 2 :(得分:0)
Unjar tlbimp.jar并查看其清单。它有一个类路径,其中args4j和com4j必须与tlbimp.jar位于同一目录中,并且需要特定的名称。名称的细节取决于构建,可能包括也可能不包括版本号。按照指示命名你的com4j和arg4j,你就可以了。