I'm attempting to run my Maven build using the usual:
mvn clean install
I'm getting a whole series of errors that read:
annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
How do I use -source 5 when performing the build. My JAVA_HOME is pointing to JDK 1.6.
Add this to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
It is also documented in the Maven FAQ.
For further information take a look at the Compiler Plugin documentation.
it's in the pom.xml. you should have <source>1.3</source> change it to
<source>1.6</source>
Related
I have a project using SwingUtilities2 which is available in Java 5 only. I'm trying to compile it using newer JDK (using Jenkins). When it comes to pure Java only I have no problems, I simply set the compile plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>${jdk.version}</compilerVersion>
<executable>${jdk.path}/bin/javac</executable>
<fork>true</fork>
</configuration>
</plugin>
Where ${jdk.path} points to Java 1.5 JDK.
When trying to add aspects, it always compiles using default jdk (1.8).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<complianceLevel>${jdk.version}</complianceLevel>
</configuration>
</plugin>
I was trying as well setting compilerId + dependencies in maven-compiler-plugin (see: http://maven.apache.org/plugins/maven-compiler-plugin/non-javac-compilers.html), but didn't help either.
Any clues how to do it?
EDIT:
Changed Jenkins job type from Maven to Free Style and invoke it using JDK 1.5. Now compiles with aspects.
I have a source code written for java 1.7. I would like to compile it for java 1.6. If I understood correctly, I need to use the options -source 1.7 -target 1.6
I am using Maven2 and Netbeans (8.0). So, I tried :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.6</target>
<compilerArguments>
<bootclasspath>/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
But I get a javacTask: source release 1.7 requires target release 1.7
I read that some people use eclipse compiler to make it work, but how can I do this if I'm using Netbeans ?
Thanks a lot for your help
EDIT Sorry it's the other way around. You can compile source 1.6 and target 1.7 but you can't compile it when source version > target version because then it couldn't handle new features of the language.
For more detail about this see Cross-Compilation Options in javac documentation http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html.
If you would have 1.6 sources you could compile them for target version 1.7 like this:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>>
in pom.xml <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin> what should be the version no?,i mean from where i will get this version no?
is this the same i.e mvn installation .
See http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source
Although the values are not explicitly defined, it follows the convention of major Java releases - 1.5, 1.6, 1.7, 1.8, etc.
I have a class which is annotated with:
#WebService(endpointInterface = "ws.AccOpsProcessorWS")
Whenever I am running mvn clean install I am getting below error:
annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#WebService(endpointInterface = "ws.AccOpsProcessorWS")
I am not able to understand the problem here. JDK version in eclipse and machine is 1.6
The error message is clear use -source 5 or higher to enable annotations. After version 5 is 1.6 :) Your pom.xml configuration is wrong.
Maven has different configuration for JDK version than eclipse, check if it is proper.
Configure JDK version in maven-compiler-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Annotations in Java are available from JDK 1.5
Are you defining what JDK to compile under? For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I have two JDK - 1.5 and 1.6.
Default JDK is 1.6 (JAVA_HOME sets to JDK 1.6)
and have env. variable JAVA_HOME_1_5 sets to JDK 1.5
I want compile maven project with JDK 1.5, so I added to pom.xml next:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<executable>${env.JAVA_HOME_1_5}/bin/javac.exe</executable>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<optimize>true</optimize>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
But maven is compiling my project with JDK 1.6!
What is wrong?
Thanks in advance!
%> JAVA_HOME=$JAVA_HOME_1_5 mvn install
Maven by default use JAVA_HOME so you can set it to jdk_1.5 just for it.
For pom way, you should add this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${JAVA_HOME_1_5}/bin/java</jvm>
<forkMode>once</forkMode>
</configuration>
</plugin>
Could it be because, as documented here, you are missing the <compilerVersion>1.5</compilerVersion> in your configuration?
can you try this. It works for me.
http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html