用于生成 Java JNA 包装器的 jnaerator 的 SimpleMeaningfulExample 将不起作用
我尝试了 jnaerator SimpleMeaningfulExample (http://code.google.com/p/jnaerator/wiki/SimpleMeaningfulExample) 和 得到:
$ java -jar jnaerator-0.9.2.jar -library Test Test.h -o . -v
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad
version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
…在 Mac OS X 10.5.8 和 Ubuntu 8.04 上,都运行 Java 1.5.0_20。
我在 Mac OS X 上切换到 1.6.0_15 并再次尝试并得到:
$ java -jar jnaerator-0.9.2.jar -library Test Test.h -o . -v
Auto-configuring parser...
Nov 20, 2009 5:12:43 PM com.ochafik.lang.jnaerator.JNAeratorConfigUtils getProp
INFO: [environment] JNAERATOR_INCLUDE_PATH=.:/usr/include
Nov 20, 2009 5:12:43 PM com.ochafik.lang.jnaerator.JNAeratorConfigUtils getProp
INFO: [environment] JNAERATOR_FRAMEWORKS_PATH=/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks:/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/Frameworks:/System/Library/Frameworks:/Library/Frameworks:/Local/Library/Frameworks/:/Users/dspitzer/Library/Frameworks
os.arch = x86_64
Nov 20, 2009 5:12:43 PM com.ochafik.lang.jnaerator.JNAerator jnaerate
INFO: Include path :
.
/usr/include
Parsing native headers...
Writing preprocessor output to '_jnaerator.preprocessed.c'
Writing preprocessor macros to '_jnaerator.macros.cpp'
line 0:-1 Failed to match any alternative with token [@-1,0:0='<no text>',<-1>,0:-1]
File: null:0
Input:
Rule: 1501:1: castExpr returns [Expression expr] : ( '(' tr= mutableTypeRef ')' inner= castExpr | e= unaryExpr );
Stack: []
line 0:-1 Failed to match any alternative with token [@-1,0:0='<no text>',<-1>,0:-1]
File: null:0
Input:
Rule: 1501:1: castExpr returns [Expression expr] : ( '(' tr= mutableTypeRef ')' inner= castExpr | e= unaryExpr );
Stack: []
line 0:-1 Failed to match any alternative with token [@-1,0:0='<no text>',<-1>,0:-1]
File: null:0
Input:
Rule: 1501:1: castExpr returns [Expression expr] : ( '(' tr= mutableTypeRef ')' inner= castExpr | e= unaryExpr );
Stack: []
Now parsing 1 text blocks
Normalizing parsed code...
Generating libraries...
JNAeration failed !
java.lang.NullPointerException
at com.ochafik.lang.jnaerator.TypeConversion.convertExpressionToJava(TypeConversion.java:1391)
at com.ochafik.lang.jnaerator.TypeConversion.convertExpressionToJava(TypeConversion.java:1223)
at com.ochafik.lang.jnaerator.DeclarationsConverter.convertVariablesDeclaration(DeclarationsConverter.java:1087)
at com.ochafik.lang.jnaerator.DeclarationsConverter.convertVariablesDeclaration(DeclarationsConverter.java:1134)
at com.ochafik.lang.jnaerator.DeclarationsConverter.convertStruct(DeclarationsConverter.java:873)
at com.ochafik.lang.jnaerator.DeclarationsConverter.outputConvertedStruct(DeclarationsConverter.java:950)
at com.ochafik.lang.jnaerator.DeclarationsConverter.convertStructs(DeclarationsConverter.java:1055)
at com.ochafik.lang.jnaerator.JNAerator.generateLibraryFiles(JNAerator.java:1102)
at com.ochafik.lang.jnaerator.JNAerator.jnaerationCore(JNAerator.java:1322)
at com.ochafik.lang.jnaerator.JNAerator.jnaerate(JNAerator.java:700)
at com.ochafik.lang.jnaerator.JNAerator$1.finished(JNAerator.java:613)
at com.ochafik.lang.jnaerator.JNAeratorCommandLineArgs$ArgsParser.parse(JNAeratorCommandLineArgs.java:127)
at com.ochafik.lang.jnaerator.JNAerator.main(JNAerator.java:256)
我做错了什么吗?
更新:我将我的问题发布到[电子邮件受保护](请参阅此线程:https://jna.dev.java.net/servlets/BrowseList?list=users&by=thread&from=2312620)并收到响应来自 JNAerator 项目所有者 Olivier Chafik。总结一下:
- 我在 JNAerator 中发现了回归,
- 他上传了一个固定的快照构建: http://jnaerator.sourceforge.net/maven/com/jnaerator/jnaerator/0.9.3-SNAPSHOT/
- 该构建效果更好,但没有生成 TestLibrary.java
- 我提交了一个错误报告: http://code.google.com/p/jnaerator/issues/详细信息?id=50
更新 #2: Olivier 在意识到缺少 TestLibrary.java 不是一个错误后再次回复,因为它默认嵌入在生成的 Test.jar 文件中。
I tried the jnaerator SimpleMeaningfulExample
(http://code.google.com/p/jnaerator/wiki/SimpleMeaningfulExample) and
got:
$ java -jar jnaerator-0.9.2.jar -library Test Test.h -o . -v
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad
version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
…on both Mac OS X 10.5.8 and Ubuntu 8.04, both running Java 1.5.0_20.
I switched to 1.6.0_15 on Mac OS X and tried again and got:
$ java -jar jnaerator-0.9.2.jar -library Test Test.h -o . -v
Auto-configuring parser...
Nov 20, 2009 5:12:43 PM com.ochafik.lang.jnaerator.JNAeratorConfigUtils getProp
INFO: [environment] JNAERATOR_INCLUDE_PATH=.:/usr/include
Nov 20, 2009 5:12:43 PM com.ochafik.lang.jnaerator.JNAeratorConfigUtils getProp
INFO: [environment] JNAERATOR_FRAMEWORKS_PATH=/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks:/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/Frameworks:/System/Library/Frameworks:/Library/Frameworks:/Local/Library/Frameworks/:/Users/dspitzer/Library/Frameworks
os.arch = x86_64
Nov 20, 2009 5:12:43 PM com.ochafik.lang.jnaerator.JNAerator jnaerate
INFO: Include path :
.
/usr/include
Parsing native headers...
Writing preprocessor output to '_jnaerator.preprocessed.c'
Writing preprocessor macros to '_jnaerator.macros.cpp'
line 0:-1 Failed to match any alternative with token [@-1,0:0='<no text>',<-1>,0:-1]
File: null:0
Input:
Rule: 1501:1: castExpr returns [Expression expr] : ( '(' tr= mutableTypeRef ')' inner= castExpr | e= unaryExpr );
Stack: []
line 0:-1 Failed to match any alternative with token [@-1,0:0='<no text>',<-1>,0:-1]
File: null:0
Input:
Rule: 1501:1: castExpr returns [Expression expr] : ( '(' tr= mutableTypeRef ')' inner= castExpr | e= unaryExpr );
Stack: []
line 0:-1 Failed to match any alternative with token [@-1,0:0='<no text>',<-1>,0:-1]
File: null:0
Input:
Rule: 1501:1: castExpr returns [Expression expr] : ( '(' tr= mutableTypeRef ')' inner= castExpr | e= unaryExpr );
Stack: []
Now parsing 1 text blocks
Normalizing parsed code...
Generating libraries...
JNAeration failed !
java.lang.NullPointerException
at com.ochafik.lang.jnaerator.TypeConversion.convertExpressionToJava(TypeConversion.java:1391)
at com.ochafik.lang.jnaerator.TypeConversion.convertExpressionToJava(TypeConversion.java:1223)
at com.ochafik.lang.jnaerator.DeclarationsConverter.convertVariablesDeclaration(DeclarationsConverter.java:1087)
at com.ochafik.lang.jnaerator.DeclarationsConverter.convertVariablesDeclaration(DeclarationsConverter.java:1134)
at com.ochafik.lang.jnaerator.DeclarationsConverter.convertStruct(DeclarationsConverter.java:873)
at com.ochafik.lang.jnaerator.DeclarationsConverter.outputConvertedStruct(DeclarationsConverter.java:950)
at com.ochafik.lang.jnaerator.DeclarationsConverter.convertStructs(DeclarationsConverter.java:1055)
at com.ochafik.lang.jnaerator.JNAerator.generateLibraryFiles(JNAerator.java:1102)
at com.ochafik.lang.jnaerator.JNAerator.jnaerationCore(JNAerator.java:1322)
at com.ochafik.lang.jnaerator.JNAerator.jnaerate(JNAerator.java:700)
at com.ochafik.lang.jnaerator.JNAerator$1.finished(JNAerator.java:613)
at com.ochafik.lang.jnaerator.JNAeratorCommandLineArgs$ArgsParser.parse(JNAeratorCommandLineArgs.java:127)
at com.ochafik.lang.jnaerator.JNAerator.main(JNAerator.java:256)
Am I doing something wrong?
Update: I posted my question to [email protected] (see this thread: https://jna.dev.java.net/servlets/BrowseList?list=users&by=thread&from=2312620) and received responses from Olivier Chafik, the JNAerator project owner. To summarize:
- I found a regression in JNAerator
- He uploaded a fixed snapshot build: http://jnaerator.sourceforge.net/maven/com/jnaerator/jnaerator/0.9.3-SNAPSHOT/
- That build worked better, but didn't generate TestLibrary.java
- I filed a bug report: http://code.google.com/p/jnaerator/issues/detail?id=50
Update #2: Olivier responded again after realizing the lack of TestLibrary.java is not a bug, since it's embedded in the generated Test.jar file by default.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,你自己已经找出问题所在了。版本问题。
该消息告诉您,您的 JRE 不知道如何执行 jar 中的类,因为 jar 中的类具有比 JRE 本身更新的版本。
jar 文件可能是用 java 1.6.x 编译的。因此,当您尝试执行它时,JRE 会抱怨
UnsupportedClassVersionError: Bad version number
,因为 JRE 的版本低于编译源代码的 JDK 版本。并且 JRE 1.5 无法读取 jar 中类的较新的类文件版本。当您切换到 Java 1.6.0_15 时,编译 jar 文件的 JDK 的主要 Java 版本和用于运行 jar 的 JRE 版本是相同的 (1.6.x),并且运行良好。
Well, you already figured out the problem yourself. Version problem.
The message is telling you that your JRE does not know how to execute the classes in the jar, because the classes in the jar have a newer version then the JRE itself.
The jar file probably was compiled with java 1.6.x. Thus when you try to execute it the JRE complains
UnsupportedClassVersionError: Bad version number
as the version of the JRE is lower then the version of the JDK the sources where compiled with. And JRE 1.5 can't read the newer class file version of the classes in the jar.As you switched to Java 1.6.0_15 the major Java version of the JDK with which the jar file was compiled and version of the JRE used to run the jar are identical (1.6.x) and it runs fine.