Java Card Converter: unsupported class file format of version 50.0
Asked Answered
P

2

5

I am attempting to generate a CAP file and an export file from the Wallet.java which comes standard in the Java Card SDK under the samples directory. I compile the class, use the converter and encounter the following:

$ javac -g -d classes/ src/com/sun/javacard/samples/wallet/Wallet.java
$ converter -debug -verbose -classdir "$JC_HOME/samples/src" com.sun.javacard.samples.wallet 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x6:0x1 1.0

Java Card 2.2.2 Class File Converter, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

parsing /home/user/javacard/java_card_kit-2_2_2/samples/src/com/sun/javacard/samples/wallet/Wallet.class
error: com.sun.javacard.samples.wallet.Wallet: unsupported class file format of version 50.0.

conversion completed with 1 errors and 0 warnings.

My Java version and javac versions are the same, Java 1.6:

$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
$ javac -version
javac 1.6.0_45

I am using JC SDK 2.2.2 on Ubuntu 14.04. The version of the converter is 1.3:

$ converter -version
Java Card 2.2.2 Class File Converter, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

I cannot seem to resolve this "unsupported class file format of version 50.0" error. I am slightly puzzled as to why I am encountering this error given Java 1.6 is version 50.0.

Has anyone else encountered the same issue?

Papilla answered 17/2, 2016 at 15:45 Comment(2)
You must use Java 1.3 to compile your .java files to .class files. Because JCDK2.2.2 converter supports Java 1.3 generated class files only.Cultivar
@Abraham, Thanks. I will give this a try.Papilla
H
7

The Java Card 2.2.2 converter supports at most the Java 5 class file format (hence it tells you that Java 6/version 50.0 is not supported). Thus, you need to specify the source compatibility/class file version when compiling the source code using newer JDK versions:

javac -g -source 1.5 -target 1.5 -d classes/ src/com/sun/javacard/samples/wallet/Wallet.java

Similarly, for Java Card 2.2.1, you would use version 1.2:

javac -g -source 1.2 -target 1.2 -d classes/ src/com/sun/javacard/samples/wallet/Wallet.java

And for Java Card 2.1.1 (JC SDK 2.1.2), you would use version 1.1:

javac -g -source 1.1 -target 1.1 -d classes/ src/com/sun/javacard/samples/wallet/Wallet.java

You can check the version of a class file with the Java class file disassembler (thanks to @cmanning for mentioning this):

javap -v -cp classes/ com.sun.javacard.samples.wallet.Wallet |grep 'version'
Heterotypic answered 18/2, 2016 at 0:2 Comment(5)
Thanks, I have already tried that and I still encounter the same result. The outcome of the javac command with the source and target specified still generates a class file with the version 50.0 format. I checked by using the following command javap -verbose src.com.sun.javacard.samples.wallet.Wallet | grep versionPapilla
@Papilla That's odd. This works fine for me with Oracle JDK 8 (1.8.0_60) on Windows 7 as well as with Oracle JDK 6 (1.6.0_30) on Ubuntu 14.04.3 LTS.Heterotypic
I think there is something wrong with my Ubuntu VM. I created a new VM and was able to control the major version through the javac source and target tags. I think I am on the right track now. Thanks for your help.Papilla
Dear Michael, I receive javac: invalid source release: 1.1 error, for -source 1.1 -target 1.1 . Why? (Other releases worked fine).Cultivar
@Abraham Seems as if the depreciated 1.1 is no longer available in Java 7 and Java 8. I have not tested this but using -source 1.2 -target 1.1 should work fine in that case.Heterotypic
I
3

You might want to look into ant-javacard that does such things (as compiler flags depending on JC SDK version) automagically. (disclaimer: i did it)

Identical answered 5/3, 2016 at 14:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.