You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ravagli Virgilio <Vi...@ansaldo-sts.com> on 2012/11/05 13:35:23 UTC

passing ant.java.version as an option

Hi everybody.
I expose my question.
I had to build JOB-4.3.4, Orbacus Java version, and I couldn't use JDK1.7 because of errors; everything would be fine using ant 1.7.1 to build Orbacus, in fact ant 1.7.1 assigns ant.java.version = 1.6 even if my JDK1.7 is 1.7.

Trying ant 1.8.4, I had the same mistakes, because this time ant.java.version was 1.7 (the same as the installed JDK).

As a matter of fact, I prefer using ant 1.8.4, so I thought to modify it: I downloaded the source dist and modified two classes, JavaEnvUtils.java and its caller Main.java, introducing "an option of mine", ajv (acronym that stands for ant java version) followed by the desired Java version.

I built my ant 1.8.4, then compiled with -ajv 1.6 and everything was good.

Imho it's a better solution than using source = 1.6 spreaded into the build file, it's more flexible.

So, that's my doubt: is there any other way, some trick,  to assign ant.java.version instead of letting it assigned by the ant code ?

The other way round, if someone thinks my choice is good, or if he's interested in it, I can publish the code.

Thanks in advance,
Virgilio Ravagli


R: passing ant.java.version as an option

Posted by Ravagli Virgilio <Vi...@ansaldo-sts.com>.
Thank you Rainer for your answer.
I see your point. But I must say, I modified the ant sources just NOT to use -source; about -target, I don't want it, because Orbacus works fine under Java 1.7, the problem is only at compile time, not at runtime, the target api isn't a problem.
I don't want to use old Java: my apps (Orbacus clients) are built on SWT, so I prefer working with newer Java version, moreover I use some features as switch over strings, and they aren't available over old Java versions.

Perhaps, your advice about <presetdef> is a good idea, I think I'll follow it, instead of my -ajv option.

Bye
Virgilio

-----Messaggio originale-----
Da: Rainer Noack [mailto:rainer@noacks.net]
Inviato: lunedì 5 novembre 2012 20.42
A: user@ant.apache.org
Oggetto: Re: passing ant.java.version as an option

Hi Virgilio,

what do you want the ant.java.version for?
The property is defined to show the current java version and is working
properly (if the ant version is newer than the java version ... - ant
1.7.1 is older than JDK 7)
It's not a good idea to change that value.

if you just want to set the <javac> attributes -source and -target by a
property, you should use |ant.build.javac.source|
<../javacprops.html#source> and/or |ant.build.javac.target which are
recognised since ant 1.7.| <../javacprops.html#source>
|You might also interested in using <presetdef>.

However, to make sure that a class is runnable with a previous jvm, it
must not only compiled with that target version but also has to be
compatible with the target api. it's a good practice to compile it with
the compiler of that jdk. See examples in <javac> manual on how to do that.

Hope that helps

Rainer

|
Am 05.11.2012 13:35, schrieb Ravagli Virgilio:
> Hi everybody.
> I expose my question.
> I had to build JOB-4.3.4, Orbacus Java version, and I couldn't use JDK1.7 because of errors; everything would be fine using ant 1.7.1 to build Orbacus, in fact ant 1.7.1 assigns ant.java.version = 1.6 even if my JDK1.7 is 1.7.
>
> Trying ant 1.8.4, I had the same mistakes, because this time ant.java.version was 1.7 (the same as the installed JDK).
>
> As a matter of fact, I prefer using ant 1.8.4, so I thought to modify it: I downloaded the source dist and modified two classes, JavaEnvUtils.java and its caller Main.java, introducing "an option of mine", ajv (acronym that stands for ant java version) followed by the desired Java version.
>
> I built my ant 1.8.4, then compiled with -ajv 1.6 and everything was good.
>
> Imho it's a better solution than using source = 1.6 spreaded into the build file, it's more flexible.
>
> So, that's my doubt: is there any other way, some trick,  to assign ant.java.version instead of letting it assigned by the ant code ?
>
> The other way round, if someone thinks my choice is good, or if he's interested in it, I can publish the code.
>
> Thanks in advance,
> Virgilio Ravagli
>
>


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


Re: passing ant.java.version as an option

Posted by Rainer Noack <ra...@noacks.net>.
Hi Virgilio,

what do you want the ant.java.version for?
The property is defined to show the current java version and is working 
properly (if the ant version is newer than the java version ... - ant 
1.7.1 is older than JDK 7)
It's not a good idea to change that value.

if you just want to set the <javac> attributes -source and -target by a 
property, you should use |ant.build.javac.source| 
<../javacprops.html#source> and/or |ant.build.javac.target which are 
recognised since ant 1.7.| <../javacprops.html#source>
|You might also interested in using <presetdef>.

However, to make sure that a class is runnable with a previous jvm, it 
must not only compiled with that target version but also has to be
compatible with the target api. it's a good practice to compile it with 
the compiler of that jdk. See examples in <javac> manual on how to do that.

Hope that helps

Rainer

|
Am 05.11.2012 13:35, schrieb Ravagli Virgilio:
> Hi everybody.
> I expose my question.
> I had to build JOB-4.3.4, Orbacus Java version, and I couldn't use JDK1.7 because of errors; everything would be fine using ant 1.7.1 to build Orbacus, in fact ant 1.7.1 assigns ant.java.version = 1.6 even if my JDK1.7 is 1.7.
>
> Trying ant 1.8.4, I had the same mistakes, because this time ant.java.version was 1.7 (the same as the installed JDK).
>
> As a matter of fact, I prefer using ant 1.8.4, so I thought to modify it: I downloaded the source dist and modified two classes, JavaEnvUtils.java and its caller Main.java, introducing "an option of mine", ajv (acronym that stands for ant java version) followed by the desired Java version.
>
> I built my ant 1.8.4, then compiled with -ajv 1.6 and everything was good.
>
> Imho it's a better solution than using source = 1.6 spreaded into the build file, it's more flexible.
>
> So, that's my doubt: is there any other way, some trick,  to assign ant.java.version instead of letting it assigned by the ant code ?
>
> The other way round, if someone thinks my choice is good, or if he's interested in it, I can publish the code.
>
> Thanks in advance,
> Virgilio Ravagli
>
>