ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scot P. Floess" <>
Subject Re: Setting final strings at compile time
Date Mon, 10 Dec 2007 19:15:54 GMT

Unfortunately, you are compiling a static final String :(

Perhaps a properties file distributed with your app could hold the 
String instead?

I wasn't proposing copying, replacing and then copying back...  What I 
meant was this:

I assume your source code is checked into some source control systems 
like Subversion or CVS?  Therefore, you probably want to copy the file 
elsewhere solely for the purpose of doing the text replacement...  
Otherwise, the file will show it is in a modified state (for example 
running "svn stat")...

You can copy the file to a new location and add that dir as part of the 
Java source path in the javac task...  It will pick up the copied file 
over the other non-modified one...  Of course, you want to keep the 
directory structure the same where you copy it over...  For example lets 
say your source is in /shared/projects/src/java/com/, you might 
want to copy to /shared/projects/generated/com/ and then do this:

<javac srcdir = "/shared/projects/src/java:/shared/projects/generated" .../>

Does that make sense?

Frederich, Eric P21322 wrote:
> Thanks for the reply and a possible solution but this seems more like a
> hack.
> Yeah, right now I have something like
> Public static final String programName = "Java Program XYZ";
> I'd like to be able to make one where that string is "Java Program XYZ -
> Development Version" automagically using ant.
> If the javac command could set properties the way the java command does
> it would be nice.
> If this isn't the case I guess I'll be stuck with a "hack" like this.
> Just seems to be a pain to explicitly copy the original to a tmp
> directory, do the replacement on the file, compile it and then copy the
> original file back.
>> -----Original Message-----
>> From: Scot P. Floess
>> Eric:
>> You mention "final Java Strings at compile time"...
>> Are you referring to actual Java as in:
>>     public static final String FOO = "some text";
>> If so, you may want to look into the <replace> task...
>> You could do something as simple as:
>> public class Main
>> {
>>     public static final String FOO = "%PROJECT NAME%";
>> ...
>> }
>> <replace file = ""  token = "%PROJECT NAME%"  value = "Some 
>> Value"/>
>> Of course, you probably want to copy off to a new 
>> dir and do 
>> the replacement there - compiling that copied version of course...
>> Frederich, Eric P21322 wrote:
>>> Hello,
>>> Is there an easy way to set final Java Strings at compile time?
>>> I know you can set properties at runtime with 
>> -Dproperty=value but could
>>> I do this at compile time?
>>> What I want to do is have one target which makes a program 
>> called "Java
>>> Program XYZ - production" and another which is called "Java 
>> Program XYZ
>>> - development".
>>> Also, it would be useful to somehow get the date and time 
>> at which it
>>> was compiled into the program.
>>> I figured this would be common, hopefully it is.  Perhaps I 
>> just don't
>>> know the right words to search on Google.
>>> Thanks in advance,
>>> ~Eric
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate
Chief Architect JavaPIM
QA Engineer OpenQabal

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message