Tuesday, September 4, 2012

Whats the encoding of my file? Compile complaints....

on Linux use... file -bi option
[cpcdev@dpcpca01 cpc]$ file -bi ./src/main/java/com/fedex/ground/dispatch/cpcs/actions/OnCallDetailActionHandler.java
text/x-java; charset=unknown
[cpcdev@dpcpca01 cpc]$ 
Or in Mac OSX
file -I --mime-encoding /prod/PersistanceLayer/src/java/domain/server/toplink/Equipment.java

Class Magic Number And Bytecode compatibility on Linux

Based on the general layout (see item #7)we need the 8th hex number to get the value. And then match the major version number with the JDK version compatibility.
major version number of the class file format being used.
J2SE 7 = 51 (0x33 hex),
J2SE 6.0 = 50 (0x32 hex),
J2SE 5.0 = 49 (0x31 hex),
JDK 1.4 = 48 (0x30 hex),
JDK 1.3 = 47 (0x2F hex),
JDK 1.2 = 46 (0x2E hex),
JDK 1.1 = 45 (0x2D hex).
In this case
[me@hostandre]$ xxd -p  org/apache/xmlbeans/impl/xsd2inst/SampleXmlUtil.class  | head -n 1 | cut -c-16
cafebabe00000030
[me@hostandre]$
The answer is: JDK 1.4 compiled and compatible...