classes compiled by Eclipse are different from classes using ANT build.xml file created by Eclipse. [message #642739] |
Thu, 02 December 2010 15:06 |
No real name Messages: 4 Registered: May 2010 |
Junior Member |
|
|
Using: (commandline) Apache Ant version 1.8.1 and Eclipse Platform Version: 3.4.2 (Ganymede)
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
[Updated on: Thu, 02 December 2010 15:12] Report message to a moderator
|
|
|
Re: classes compiled by Eclipse are different from classes using ANT build.xml file created by Eclip [message #642855 is a reply to message #642739] |
Fri, 03 December 2010 00:45 |
Olivier Thomann Messages: 518 Registered: July 2009 |
Senior Member |
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03721 seconds