Finally to finish this I tried a mini maven project containing the following
class:
package zzzzTest;
public class Test {
public void foo() {
System.out.println(new StringBuilder("Hello world!"));
assert true;
}
}
Running mvn install gave me (stripped for the relevant part):
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ zzzzTest
---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory
C:\Users\sebastian.oerding\workspaces\workspace\zzzzTest\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ zzzzTest ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e.
build is platform dependent!
[INFO] Compiling 1 source file to
C:\Users\sebastian.oerding\workspaces\workspace\zzzzTest\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR]
/C:/Users/sebastian.oerding/workspaces/workspace/zzzzTest/src/main/java/zzzzTest/Test.java:[6,17]
C:\Users\sebastian.o
\Test.java:6: not a statement
[ERROR]
/C:/Users/sebastian.oerding/workspaces/workspace/zzzzTest/src/main/java/zzzzTest/Test.java:[6,23]
C:\Users\sebastian.o
\Test.java:6: ';' expected
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.138 s
[INFO] Finished at: 2015-03-30T10:23:21+02:00
[INFO] Final Memory: 9M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on
project zzzzTes
[ERROR]
/C:/Users/sebastian.oerding/workspaces/workspace/zzzzTest/src/main/java/zzzzTest/Test.java:[6,17]
C:\Users\sebastian.o
\Test.java:6: not a statement
[ERROR]
/C:/Users/sebastian.oerding/workspaces/workspace/zzzzTest/src/main/java/zzzzTest/Test.java:[6,23]
C:\Users\sebastian.o
\Test.java:6: ';' expected
[ERROR] -> [Help 1]
Hence new available API may be a special case but using features such as
assertions not supported does really cause a compiler error (the maven
installation used as JDK 1.6)
With regards
Sebastian
-----Ursprüngliche Nachricht-----
Von: Lin Ma [mailto:[email protected]]
Gesendet: Montag, 30. März 2015 09:56
An: Maven Users List
Betreff: Re: about source and target in maven-compiler-plugin
Thanks all the same Sebastian. Your reply is very helpful and bring us further
thoughts.
regards,
Lin
On Mon, Mar 30, 2015 at 12:47 AM, Sebastian Oerding <
[email protected]> wrote:
> Hi Lin,
>
> I just tried my example and Maxim is right. I thought that the source
> should take the API compatibility into account it seems that it is not
> this way. Hence if the classes are successfully compiled (which
> requires a JDK >
> 1.5) and you are executing them with Java 1.5 the StringBuilder class
> will not be in place -> ClassNotFoundException (the class format
> should be as needed for Java 1.5 due to the target).
>
> However I will not tell anymore about it as I'm not completely sure
> about the moment and I do not have the time to really dig into this. Sorry.
> Detailed information about this is available in the net. In an earlier
> email someone already provided links for the Maven documentation.
>
> Furthermore details about setting the compiler level can be found for
> example in the Sun Certified Java Programmer Study Guide.
>
> With regards
> Sebastian
>
> -----Ursprüngliche Nachricht-----
> Von: Lin Ma [mailto:[email protected]]
> Gesendet: Montag, 30. März 2015 09:38
> An: Maven Users List
> Betreff: Re: about source and target in maven-compiler-plugin
>
> Hi Maxim,
>
> Why compiler will not fail? Supposing StringBuilder is a class in JDK
> 1.6, but we force compiler to use 1.5 which has no such class? Please
> feel free to correct me if I am wrong.
>
> regards,
> Lin
>
> On Mon, Mar 30, 2015 at 12:33 AM, Maxim Solodovnik
> <[email protected]>
> wrote:
>
> > If I'm not mistaken compiler will not fail in this case BUT the
> > application will fail in runtime (in case Java 1.5 is used) due to
> > StringBuilder class is missing in JDK
> >
> > On Mon, Mar 30, 2015 at 1:20 PM, Lin Ma <[email protected]> wrote:
> >
> > > Thanks Sebastian,
> > >
> > > 1. I am using JDK 1.7/1.8 for both development and deployment in
> > > runtime, shall I change 1.5 of source and target to 1.7/1.8?
> > >
> > > 2. In your example, "for example you can write source code using a
> > > JDK
> > 1.6
> > > which is compliant to Java 1.5. However you can also use the
> > StringBuilder
> > > class which does not exist in Java 1.5", I think using JDK 1.6
> > > specific feature but using 1.5 complier will fail? No? Please feel
> > > free to correct me.
> > >
> > > regards,
> > > Lin
> > >
> > > On Mon, Mar 30, 2015 at 12:14 AM, Sebastian Oerding <
> > > [email protected]> wrote:
> > >
> > > > source -> The level (JDK version) to which the source code must
> > > > be compliant to, for example you can write source code using a
> > > > JDK
> > > > 1.6
> > which
> > > > is compliant to Java 1.5. However you can also use the
> > > > StringBuilder
> > > class
> > > > which does not exist in Java 1.5 target -> The class version of
> > > > the generated class files. The class
> > > format
> > > > changes with some Java version, for example as some stuff may be
> > > > added
> > > for
> > > > performance reason. For example if a new byte code instruction
> > > > comes up (like 'invokedynamic') this really makes a change. Or
> > > > another example
> > > (I'm
> > > > not really sure about it): As far as I think a stack map has
> > > > been added from Java 5 to Java 1.6. This should improve
> > > > performance and makes
> > subtle
> > > > differences when ClassNotFoundException are thrown. You can use
> > > > a JDK
> > to
> > > > compile code for different but lower versions. This way can
> > > > benefit
> > from
> > > > some optimizations which weren't available with the old JDK and
> > > > are compatible.
> > > >
> > > > With regards
> > > > Sebastian
> > > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Lin Ma [mailto:[email protected]]
> > > > Gesendet: Montag, 30. März 2015 07:46
> > > > An: Maven Users List
> > > > Betreff: about source and target in maven-compiler-plugin
> > > >
> > > > Hello Maven masters,
> > > >
> > > > For maven-compiler-plugin(a sample below), have a quick question.
> > > > I
> > read
> > > > this document
> > > > (http://maven.apache.org/plugins/maven-compiler-plugin/
> > ),
> > > > and confused what means source and target 1.5 here, it seems it
> > > > is an internal version number of Maven, independent of JDK?
> > > >
> > > > <plugin>
> > > > <artifactId>maven-compiler-plugin</artifactId>
> > > > <version>2.3.2</version>
> > > > <configuration>
> > > > <source>1.5</source>
> > > > <target>1.5</target>
> > > > </configuration>
> > > > </plugin>
> > > >
> > > > thanks in advance,
> > > > Lin
> > > >
> > > > ----------------------------------------------------------------
> > > > --
> > > > --- To unsubscribe, e-mail: [email protected]
> > > > For additional commands, e-mail: [email protected]
> > > >
> > >
> >
> >
> >
> > --
> > WBR
> > Maxim aka solomax
> >
>