Question

I have a piece of code which has been compiled with java version 1.5 ( both source and target are set to 1.5 on maven compile plugin )

<source>1.5</source>
<target>1.5</target>

What I want to do now is to compile them for an application ( the source is a plug in for a main application )which is upgraded to java version 1.6

In this case;

do I need to use compile plugin with the parameters;

<source>1.5</source>
<target>1.6</target>

or

<source>1.6</source>
<target>1.6</target>

plus; do I need to set the java home and path to java 1.6 or plugin will use the correct artifacts ( may be by downloading ) to compile for java 1.6 ??

regards..

Was it helpful?

Solution

First of all, you don't absolutely have to recompile on Java 1.6. Your Maven artifacts compiled using Java 1.5 will probably work fine when used by a Java 1.6 application running on a Java 1.6 platform.

If you do want to recompile, then either combination should work. In fact, they are for all intents and purposes identical since there were no relevant changes in the language between Java 1.5 and 1.6. However, there is value in compiling and running the unit tests on Java 1.6 ... just in case some library change causes your code to fail on the newer platform.

OTHER TIPS

You should use the Java 1.6 in your JAVA_HOME and your plugin should run if you use target/source with 1.5 this should run with 1.6. Except if you are using particular things from Java 1.6 (String.isEmpty() for example)...

Always set source and target in your pom.xml file

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top