Maven creates class file 50.0, should be 49.0 - java

This is my setup:
JDK 1.5 and JDK 1.6 installed, JAVA_HOME points to JDK 1.6
pom.xml uses maven-compiler-plugin with <source>1.5</source> and <target>1.5</target>
mvn --version displays Java version: 1.6.0_06
Maven 2.2.1
Is it correct that Maven 2.2.1 creates class files with file version 50.0 with this configuration?

if I understand Maven correctly, it just means it runs on the 1.6 runtime. The settings in the pom should determine the generated classfile format.

Related

What if I don't specify source and target version of java in maven pom.xml?

Anyone please tell me what is the default version of source and target version of java used by maven when its not specified in pom.xml
Maven compiles with the maven compiler plugin. The default version is java 1.5 for source and target.
https://maven.apache.org/plugins/maven-compiler-plugin/

Maven compiler plugin specification

If my JDK version is 1.8 and I suppose my project will be running on JDK 1.8. Do I still need to specify this maven property in my pom file?
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
I thought if I am using Jdk 1.8 and I want my project to be compatible with JDK 1.7, then I need this specification. Is that true?
You must always specify these properties, otherwise Maven will default them to 1.5.

Jenkins maven release plugin with different jdk

I want to perform a maven release that compile java 1.8 code on a Jenkins install that runs on jdk 1.7
I have a project that I compile with java 1.8 using the JDK Parameter Plugin . It works when doing a regular build.
When I do a maven release using the maven release plugin, it forks a JVM with java 1.7 instead of the version specified on the plugin. I guess that it takes the java version in the environment.
If I set JAVA_HOME for that job to 1.8 it works.
I am trying to find a solution where I don't have to override the JAVA_HOME in all my jobs.
I tried to use the solution from a similar post which fixed OP problem by forcing a compiler version:
<properties>
<jee.level>1.8</jee.level>
<jdk.level>1.8</jdk.level>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jee.level}</source>
<target>${jdk.level}</target>
</configuration>
</plugin>
but I end up with:
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project redeem-commons-test: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
any help would be appreciated.
The best solution I found so far is to upgrage the JDK of the container in which jenkins runs and add a JAVA_OPTS to the latter to support the previous JDK version. e.g. -Djava.version=1.7
This way I can build and maven release projects that are java 7 or java 8.

Maven current project compiled with java 1.6 which has 2 dependencies on java 1.7 and 1.6

My current Maven project is compiled with 1.6
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
However, it has 2 dependencies - say dep1.7 one of which is compiled with 1.7 and the other one, say dep1.6 is compiled with 1.6. Both dependencies cannot change their versions, i.e 1.7 dependency cannot be compiled with 1.6 and vice versa.
Is there a way out of this one?
I can upgrade my application to compile with java 1.7.
Right now, my unit tests which use the dep1.7 fails with a Unsupported major.minor version 51.0 as expected.
How about compiling dep1.6 with Java 7. It should be doable since it should be forward compatible unless I am missing something.

Error abotut dynamic web module version reported by STS

I've created a web project in STS 2.9.2 using Spring 3.0.6 and Maven 3.0.3. I've created some pages and code with no errors.
I've upgraded Spring libraries version from 3.0.6 to 3.1.2 in project's pom.xml and now I get following error message:
Dynamic Web Module 3.0 requires Java 1.6 or newer.
Dynamic web module version and Java compiler version in project's faces are set to 2.5 and 1.6 respectively. Also set JRE system library for my project to 1.6.
I've tried to remove Maven nature and then add it again and JRE system library is set to JSE 1.5 automatically (but I have no Java 1.5 installed). I change JRE system library to 1.6 manually (to fix STS complaint about the JRE system library version) but error about dynamic web module remains.
I've googled for a fix but I've found nothing.
How can I solve that error?
First check that your project is configured probably to use Java 1.7.
Right click your project > Properties > Java Compiler and set “Compiler compliance level” to 1.7.
Next from the menu on the left select Project Facets > Java and set its version to 1.7
If you didn’t find 1.7 as one of the drop down options in the previous preferences, then you have to add it to eclipse first.
Navigate to eclipse Preferences > Java > Installed JREs, click Add, and locate your installed Java path.
Open your project’s pom.xml and add this plugin tag
<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>
Finally, right click on your project > Maven > Update Project…
Source: http://qussay.com/2013/09/13/solving-dynamic-web-module-3-0-requires-java-1-6-or-newer-in-maven-projects/
I couldn't solve this problem by modifying pom.xml, or deleting project and workspace files and restarting eclipse.
I fixed it by disabling Maven nature of the project and then re-enabling it.
I have the same problem. I delete project from eclipse. In console I type mvn eclipse:clean. After this in Eclipse I imported a maven project and it was a solution.

Categories