classes compiled by Eclipse are different from classes using ANT build.xml file created by Eclipse.https://www.eclipse.org/forums/index.php/mv/msg/201251/642739/#msg_642739
I've a project in Eclipse which consists of 117 Java files. When I do an Eclipse buildall 135 .class file are generated (135 instead of 117 because inner classes are used).
I created an build.xml file for Ant using File->Export->Ant buildfile. I checked 'create target to compile project using Eclipse compiler' . When I run this ant file from the commandline 137 .class file are generated and the programs can be run. I've noticed a few things and have a few questions:

1) I used a diff program called 'beyond compare' (BC) to compare the generated classes by Eclipse and Ant. It turns out that the generated classes are different.
2) The Ant file generated two extra .class files like JCatImportMapping$1.class. There is a JCatImportMapping.java file which contains two innerclasses which results in .class files like JCatImportMapping$JCatImportMappingItem.class. I've decompiled the JCatImportMapping$1.class using a program called JD-GUI (uses JC-core) and the contents is
package com.company.dataimport;
class JCatImportMapping$1
{
}
Hence the .class is in principle empty !!
3) I've decompiled a few .class file generated by Eclipse and Ant. Functionally they probably are the same but the decompiled sourcecode is different. Static blocks at the bottom instead of at the top, if statements where arguments are split across multiple lines, even two if blocks which have changed places. I decompiled x.class generated by Eclipse, decompiled it and changed file x.java with the decompiled version. When I tell eclipse to compile the x.java file the generated x.class file is different then the original x.class

My questions:
-------------------------------------------
1) Does anyone know why the classes created by Eclipse and the Ant file created by Eclipse generate are different .class files?
2) Is there a way to instruct Ant to geneate the same .class files as Eclipse?
3) Is there a way to see what exactly Eclipse compiles and with what parameters when I do a buildall.
3) Does anyone know where the two new .class come from and what there function is. To me it sounds like they don't do anything.
4) With regard to decompiling. I've read at http://www.faqs.org/docs/Linux-HOWTO/Java-Decompiler-HOWTO.h tml that to check if a decompiler functions properly one has to compile the sourcode of the the decompiled .class file and then the orginal .class and the newly created one have to be the same. This clearly isnt' the case here. Do I need another decompiler or is this what one can expect?

Any help is very much appreciated.

Jan ]]>No real name2010-12-02T15:06:45-00:00Re: classes compiled by Eclipse are different from classes using ANT build.xml file created by Ecliphttps://www.eclipse.org/forums/index.php/mv/msg/201251/642855/#msg_642855

No Real Name wrote on Thu, 02 December 2010 10:06

Using: (commandline) Apache Ant version 1.8.1 and Eclipse Platform Version: 3.4.2 (Ganymede)
...
1) Does anyone know why the classes created by Eclipse and the Ant file created by Eclipse generate are different .class files?

Are you sure the Eclipse compiler is used inside your ant file ?
Do you have a line like this ?
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />

Quote:

2) Is there a way to instruct Ant to generate the same .class files as Eclipse?

If you use the same compiler, you should get the same .class files.

Quote:

3) Is there a way to see what exactly Eclipse compiles and with what parameters when I do a buildall.

Once you are sure that you are using the Eclipse compiler inside your ant task, if you specify a nested compilerarg element inside the javac ant task, you can get an xml log using "-log c:/log.xml". This will tell you exactly what .class files are generated for each source file, all warnings, all compile errors if any, all command line arguments, all compiler options,...

Quote:

3) Does anyone know where the two new .class come from and what there function is. To me it sounds like they don't do anything.

I would not be surprised that you are using javac and javac creates synthetic anonymous types.

Quote:

4) With regard to decompiling. I've read at http://www.faqs.org/docs/Linux-HOWTO/Java-Decompiler-HOWTO.h tml that to check if a decompiler functions properly one has to compile the sourcode of the the decompiled .class file and then the orginal .class and the newly created one have to be the same. This clearly isnt' the case here. Do I need another decompiler or is this what one can expect?

There is absolutely no guarantee that decompiled source code is identical to the original source code.

Olivier]]>Olivier Thomann2010-12-03T00:45:33-00:00Re: classes compiled by Eclipse are different from classes using ANT build.xml file created by Ecliphttps://www.eclipse.org/forums/index.php/mv/msg/201251/642972/#msg_642972
For starters, thanks a lot for your help (you wer the only one) it was very usefull

Checked the build file and it indeed contains the line line you mentioned in the following part:

You were correct that I'm using the JDK because (hitting wall slightly with head) the default target is 'build' and not 'build-eclipse-compiler'. I assumed that eclipse would set the eclipse version as default which it doesn't.

I've installed vizant to visualize the buildfile and now its much clearer what happens. I hoped that Eclipse 3.4.x would also be able to visualize the buildfile, but I can't seem to find it. BTW do you perhaps know of a better visualization tool then vizant ?

I've built my project again and now I get 135 files and all are excactly the same as the Eclipse version.

I've done some more digging with regard to decompiling and the info I read was incorrect, you were correct again.

I assume this allow me to compile using the eclipse compiler the sources on another machine which doesn't have eclipse installed (which is what I want in the end).

One last question. I assume that apart from the fact that 2 extra classes (empty anonymous inner classes I assume) were introduced by the JDK compiler the code executes in the exaclty same way. I know I'm perhaps a bit paranoid....
]]>No real name2010-12-03T15:00:16-00:00Re: classes compiled by Eclipse are different from classes using ANT build.xml file created by Ecliphttps://www.eclipse.org/forums/index.php/mv/msg/201251/643015/#msg_643015
The execution should be identical. My point was that if you use the Eclipse IDE and the same compiler from the jdt.core ant adapter and the eclipse batch compiler, you should get exactly the same .class files (same contents, same number of .class files).

I just hope that you know have the right settings to compile everything using the Eclipse compiler.