我尝试了 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)
…在运行 Java 1.5.0_20 的 Mac OS X 10.5.8 和 Ubuntu 8.04 上。
我在 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)
难道我做错了什么?
更新:我将我的问题发布到users@jna.dev.java.net(请参阅此线程:https ://jna.dev.java.net/servlets/BrowseList?list=users&by=thread&from=2312620 )并收到 Olivier 的回复Chafik,JNAerator 项目所有者。总结一下:
- 我在 JNAerator 中发现了一个回归
- 他上传了一个固定的快照构建:http: //jnaerator.sourceforge.net/maven/com/jnaerator/jnaerator/0.9.3-SNAPSHOT/
- 该构建效果更好,但没有生成 TestLibrary.java
- 我提交了一个错误报告:http ://code.google.com/p/jnaerator/issues/detail?id=50
更新 #2: Olivier在意识到缺少 TestLibrary.java 不是错误后再次做出回应,因为它默认嵌入在生成的 Test.jar 文件中。