On Wed, Jun 13, 2012 at 06:59:05PM +0200, Jörg Schaible wrote:
> Gilles Sadowski wrote:
> 
> > On Wed, Jun 13, 2012 at 03:05:13PM +0200, Xavier Detant wrote:
> >> The byte code generated by the compiler is totally independent from the
> >> JVM that will be used to run it.
> > 
> > Totally independent? Compiling with 1.7 and running with 1.6 will raise
> > this error:
> >   Unsupported major.minor version 51.0
> 
> Then you have setup your POM wrongly.

No, this output was obtained from running "ant" (not a "commons" project).
It just shows that there is no forward compatibility. :-)

> Target should always be the lowest 
> supported JDK.
> 
> Nevertheless we have profiles in one of our parent POMs to select different 
> JDK versions to compile and run the tests. My settings.xml contains:
> 
> ============= %< =============
>             <profile>
>                 <id>java-1.3</id>
>                 <properties>
>                     <JAVA_1_3_HOME>/opt/sun-jdk-1.3.1.21</JAVA_1_3_HOME>
>                 </properties>
>             </profile>
>             <profile>
>                 <id>java-1.4</id>
>                 <properties>
>                     <!--JAVA_1_4_HOME>/opt/blackdown-
> jdk-1.4.2.03</JAVA_1_4_HOME-->
>                     <JAVA_1_4_HOME>/opt/ibm-jdk-
> bin-1.4.2.13_p9</JAVA_1_4_HOME>
>                 </properties>
>             </profile>
>             <profile>
>                 <id>java-1.5</id>
>                 <properties>
>                     <JAVA_1_5_HOME>/opt/ibm-jdk-
> bin-1.5.0.12_p5</JAVA_1_5_HOME>
>                     <!--JAVA_1_5_HOME>/opt/sun-jdk-1.5.0.22</JAVA_1_5_HOME--
> >
>                 </properties>
>             </profile>
>             <profile>
>                 <id>java-1.6</id>
>                 <properties>
>                     <JAVA_1_6_HOME>/opt/sun-jdk-1.6.0.24</JAVA_1_6_HOME>
>                 </properties>
>             </profile>
> ============= %< =============

Yes, that was something like that which I had in mind. I posted here because
I wanted to know whether this sort of customization can be done at a higher
level. Like: Is it possible to "import" sections of the "settings.xml" file?

E.g. someone could have set up a snippet in a file "select_jdk.settings.xml"
with:

             <profile> 
                 <id>java-1.6</id>
                 <properties>
                     <JAVA_1_6_HOME>${JAVA_1_6_HOME}</JAVA_1_6_HOME>
                 </properties>
             </profile>

which could be imported in our personal "settings.xml"; then, on the
command-line:

 -DJAVA_1_6_HOME=/opt/sun-jdk-1.6.0.24

Thus what I mean: Is there a repository of snippets, or does everyone build
up his own "settings.xml" by endless copy/paste?

> 
> i.e. even if I run Maven with Java 7, I can use the profile to select 
> something different.
> 
> >> So I think the point is not «How to compile
> >> using the right JDK?» but «How to run with using the right JVM?» Am I
> >> wrong?
> > 
> > It is both: compiling _and_ running the tests.
> >
> > I should be able to do all combinations, i.e.:
> >  1. Compile with javac 1.6 and run with java 1.6
> >  2. Compile with javac 1.7 and run with java 1.7
> >  3. Compile with javac 1.6 and run with java 1.7
> > (and similarly with s/6/5/)
> > 
> >> If so, this can't be done at compile time, so it can't be done via
> >> maven, unless you use antrun maven's plugin to create a ant task to
> >> launch your program.
> > 
> > The point is to compile and then _run_ the unit tests, assuming that the
> > code conforms to the syntax of Java 5, Java 6, and Java 7, respectively.
> > 
> > In particular, if some source code is Java 5, it should be compatible with
> > more recent versions of the Java language, thus be compilable with more
> > recent implementations of javac.
> > The ultimate goal is to check that the unit tests pass independently of
> > the javac and java versions.
> 
> You can use Java 7 to compile and use a different JDK to run the tests:
> 
> $ java -version
> java version "1.7.0_04"
> Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
> Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
> $ mvn clean package
> $ mvn -P java-1.5 test
> 
> The animal sniffer plugin can ensure on top of it, that no Java 7 stuff is 
> used, even if it is used to compile for Java 5.


Thanks for the info,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to