views:

306

answers:

1

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&amp;by=thread&amp;from=2312620) and received responses from Olivier Chafik, the JNAerator project owner. To summarize:

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.

A: 

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.

jitter
I figured out *half* the problem myself. JNAeration failed (with a NullPointerException) after I switched to Java 1.6.0_15. I'm hoping someone knows why.
Daryl Spitzer
Oops. Missed that. Just skipped over really reading the whole second output paste. As it looked like running normally
jitter