Maven project compiler-plugin target isn't activated - java

I have a maven web-service project and I use a configuration for the "compiler-plugin", set to use 1.6 version source and target:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I have configured in my pc version 1.8 of the Java Compiler (JDK).
I run tomcat with the 1.7 JRE (Java Runtime Environment) and I get the following exception in the logs:
Unsupported major.minor version 52.0
which is refered to the uncompatibility of the compiled version with the runtime.
If I change my java compiler to the version 1.7, and recompile the project, the projects deploys correctly to tomcat and I dont get any log error.
Is there any command for maven to check which compiling version it reads from the configuration? Is it a known problem of the plugin?

Related

maven-compiler-plugin broken on linux?

I have a maven project. In the pom.xml file the following is stated:
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
</plugins>
</build>
...
AFAIK this is correct, it should build against JDK 7.
I run a Debian based Linux dist and when I do mvn clean install it seems to always build against the javac version I have set in my os.
I've tried reading up on what the plugin exactly does https://maven.apache.org/plugins/maven-compiler-plugin/, but it doesn't really state how.
An example is I have javac 8 running on my os. When I invoke mvn clean install, the project compiles against JDK 8 and not JDK 7 as stated in the pom.xml. Why is this?
By default the maven-compiler-plugin uses %JAVA_HOME%/bin/javac to compile, unless:
you set the executable-parameter to a different location
you use Toolchains, which seems to match your requirements, i.e a different Java Runtime for Maven compared to the JDK for the maven-compiler-plugin.
Source and target settings are just passed to the javac compiler as parameters. The javac installed on the machine is used.

Compile error when doing Maven install

I was trying to install the dependency packages into my location maven repository with running mvn clean install from my maven project.
But unfortunately. I got a compile error for some source files which said :annotations are not supported in -source 1.3(use -source 5 or higher to enable annotations)#override.
After researching. I found I need to specify the source version of my maven project.
So I add the following configuration in the POM.
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Actually. It does work fine. But what makes me confused is where does the JDK1.6 comes from and make the Maven compile work ? I didn't have the JDK1.6 install in my computer(Currently, the available JDK installed in my computer is JDK1.8), Thanks.
Later versions of Java allow you to compile your program as earlier versions. Since you have Java 8 installed you can compile your program as a Java 6 one that will run on a machine with only the 1.6 JRE. The limitation is that you can't use any of the language features added in the Java 7 and 8 releases.

Incompatible Compliance level

My spring project builds successfully when I build using intellij maven window to build it. But when I configure it to deploy in tomcat server(by setting run configurations in intellij) it gives an error as follows.
Compliance level '1.4' is incompatible with target level '1.7'. A compliance level '1.7' or better is required
My maven pom.xml defines compiler plugin as follows.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
and my pc's JAVA_HOME is pointed to jdk 1.7
What is this error means. How to change compliance level 1.4 to 1.7
This application works well when I manually deploy it to tomcat server

How do I set JDK version for gmaven plugin?

Is it possible to force the gmaven plugin to use a different JDK than the one specified in JAVA_HOME? We need to build a specific project using Java 7, but most developers will have JAVA_HOME set to a Java 6 install as all our other projects are still on Java 6.
The error message we get is:
[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs (default) on project XYZ: Execution default of goal org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs failed: An API incompatibility was encountered while executing org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs: java.lang.UnsupportedClassVersionError: <snip> : Unsupported major.minor version 51.0
Thanks!
The Maven Enforcer plugin is an easy way to require a specific JDK version.
you can specify JAVA_HOME for maven task in ide or bat/sh file for example
Intellige Idea
and no need to change system environment variables
Example configuration from maven-compiler-plugin
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
The maven by default uses Java 1.4, not the Java set in the JAVA_HOME variable.
You can set an alternate jdk in the maven-complier-plugin configuration. See here

setting -source to 1.5, it is set to 1.3 apparently

I am using eclipse, with maven2 plugin.
I am trying to setup a simple annotations based spring 3 mvc web application.
So I went to RunAs and clicked on 'maven build', I set the goal as 'compile'.
When it compiles, I get the error message:
E:\dev\eclipse\springmvc2\src\main\java\web\HomeController.java:[5,1] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Controller
so far I modified the eclipse.ini to use the jdk. I also made sure under preferences, it is at java 1.6.
Not sure where else to change the java version?
(I am assuming source 1.3 means java 1.3 and that I need it to be at least version 1.5 compatible)
You should also set a proper source version in pom.xml (because maven can make builds without Eclipse, so it can't use Eclipse preferences):
<project ...>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
...
</project>

Categories

Resources