ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.kitt.rei...@gmail.com>
Subject Re: General Concept Question
Date Tue, 01 Nov 2011 16:51:46 GMT
the ant task javac will call the command line javac for files that
are changed. In your case ResumeFileGenerator.java has not
changed so only ResumeConstants.java will be compiled to ResumeConstants.class.

However, ResumeFileGenerator.class does not contain references to
ResumeConstants.class,
the constants have been compiled to byte code constants and so you get
the constants that were around when ResumeFileGenerator.class was originally
compiled. For your use-case, it would make more sense to create a
program.configs.property
resource and read in the resource. Alternatively provide a static
method to access the constant in
the generated file:

public class ResumeConstants {


private static final boolean FOO = true;
public static final boolean FOO() {
  return FOO;
}
}


public ResumeFileGenerator {

 if (ResumeConstants.FOO()) { /* otherwise, print nothing */
    System.out.println("XXX");
     }



Peter





On Tue, Nov 1, 2011 at 2:46 PM, Rhino <rhino1@sympatico.ca> wrote:
>
>
> On 2011-11-01 01:42, Stefan Bodewig wrote:
>>
>> On 2011-10-31, Rhino wrote:
>>
>>> I have an Ant script that changes the value of some constants in a
>>> constants file that is used later by a Java program. The edits are
>>> pretty trivial in nature - three booleans get set to false instead of
>>> their normal value of true - and then the Java program which uses them
>>> is supposed to change its behavior according to the new values of the
>>> booleans. But even though I am sure the edits are being done and that
>>> the .java files are only compiled after the edits have been completed,
>>> the Java program continues to see the booleans as true, even when they
>>> are not.
>>
>> By constants you mean "static final" variables?
>
> Yes.
>>
>> javac inlines static final primitives so in
>>
>> public class A {
>>     public static final boolean FOO = true;
>> }
>> public class B {
>>     public static boolean BAR = A.FOO;
>> }
>
> No. What I have is a Constants file that looks like this before the build
> script starts running:
>
> public class ResumeConstants {
>
> public static final boolean FOO = true;
> }
>
> That is referenced by another Java class that looks like this:
>
> public ResumeFileGenerator {
>
>  if ResumeConstants.FOO { /* otherwise, print nothing */
>     System.out.println("XXX");
>      }
>
>  My build script prompts the person running the script whether FOO should be
> true or false on this run. If it should be false, ResumeConstants is edited
> (and saved), then all the files are compiled, then ResumeFileGenerator runs.
> But ResumeFileGenerator behaves as if FOO is true, even though it has been
> changed to false. A display of FOO in ResumeFileGenerator shows it to be
> true, even though I know I set it to false.
>>
>> B won't even reference the A class after compilation and BAR is set to
>> true.  If you later change the value in A and re-compile A but not B the
>> value in B will not change.  You just re-compile B as well.
>>
>> This is a Java concept, not an Ant concept 8-)
>
> My Java is rusty too, I'm afraid. I'm not sure if your remark still applies
> now that I've clarified what's actually happening in the code?
>>
>> Stefan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


Mime
View raw message