Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » classes compiled by Eclipse are different from classes using ANT build.xml file created by Eclipse.
classes compiled by Eclipse are different from classes using ANT build.xml file created by Eclipse. [message #642739] Thu, 02 December 2010 15:06 Go to next message
No real name is currently offline No real nameFriend
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 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier ThomannFriend
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
Re: classes compiled by Eclipse are different from classes using ANT build.xml file created by Eclip [message #642972 is a reply to message #642855] Fri, 03 December 2010 15:00 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 4
Registered: May 2010
Junior Member
Hi Olivier

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:

<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>

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.

the buildfile also contains the following section.
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>

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....
Re: classes compiled by Eclipse are different from classes using ANT build.xml file created by Eclip [message #643015 is a reply to message #642972] Fri, 03 December 2010 16:31 Go to previous message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
When I want to find out what is going on when running an ant script, I use debug tracing. Then each target called is logged in the console and that helps in general.

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.

Olivier
Previous Topic:Eclipse gets slow down after some time
Next Topic:Java Program wont run properly.
Goto Forum:
  


Current Time: Fri Apr 26 12:20:03 GMT 2024

Powered by FUDForum. Page generated in 0.03721 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top