ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: Generics and compilation problems
Date Mon, 15 Jun 2009 13:53:29 GMT


Hi,

-----Original Message-----
From: Lorenzo Carnevale [mailto:lorenzo.carnevale@innovery.it] 
Sent: Monday, June 15, 2009 11:31 AM
To: user@ant.apache.org
Subject: Generics and compilation problems

/*
[...]
What I want to ask is: is it possible to log somehow which "javac.exe" is actually being used
to do the compilation task?
Thanks
         Lorenzo
*/

some thoughts =

1. if you are not using <javac> with
fork="true"
executable=path/to/your/javac.exe
includejavaruntime="false"
includeAntRuntime="false"
means using another javac as the default on your build machine and setting up
a special classpath,  the javac version from path is used.
So you'll get the javac version via ${java.version} which is automatically set
(to see all java properties, use <echoproperties prefix="java"/>).


2.
check the javac version with javac -version, maybe catching the output (stderr)
in a property, f.e. =
<script language="ruby">
 <![CDATA[
 $project.setProperty "javacversion",
 `javac -version 2>&1`.scan(/javac (.+)/)[0].to_s
 ]]>
</script>

3.
you might check the major/minor version of a compiled class if there are class
files that got compiled in your build before the error occured =

/**
* reads the major/minor version from a class file
*
* the first 4 bytes = 0xCAFEBABE (magic number)
* the next 2 bytes represent the major/minor version 
* 
* major  minor Java platform version 
 * 45       3           1.0
 * 45       3           1.1
 * 46       0           1.2
 * 47       0           1.3
 * 48       0           1.4
 * 49       0           1.5
 * 50       0           1.6
 * 
 * see Java VM Spec =
 * http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html
 * 
 */

public class ClassVersionChecker {
    public static void main(String[] args) throws IOException {
        for (int i = 0; i < args.length; i++)
            checkClassVersion(args[i]);
    }

    private static void checkClassVersion(String filename)
        throws IOException
    {
        DataInputStream in = new DataInputStream
         (new FileInputStream(filename));

        int magic = in.readInt();
        if(magic != 0xcafebabe) {
          System.out.println(filename + " is not a valid class!");;
        }
        int minor = in.readUnsignedShort();
        int major = in.readUnsignedShort();
        System.out.println(filename + " : " + major + "." + minor);
        in.close();
    }
}



Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message