Maven can't change the library set by default - java

I have this problem when creating a maven project. I can't change the JRE library from J2SE-1.5 to Java-S.E 1.6 or 1.7 without errors. (and even with the J2SE-1.5, I have a warning)
I know that it's set by default, so I changed the maven compiler plugin.pom file but I still get the same error.
Here is what i modified in my pom.xml file:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>

Just changing the java version in your pom.xml is not good enough. You need to have the environment variable JAVA_HOME set to the version you intend to use. Maven uses this variable to build your project, so JAVA_HOME and the compiler plugin version must match.

Related

maven compiler in intellij

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
What is the point of using maven in intellij if it dose not work without setting the correct JDK under various intellij options?
What I mean is that now with intellij I have to set the JDK in 3 different places.
File->Setting->Build->Compiler
File->Project Structure->Project
File->Project Structure->Modules
While I aspect expect that when i compiler on the right side where are the maven options it works just by watching the pom file.
i think that depends on what type of project you want to make but personally i find maven nice to use because you can set up several actions in the pom file (for example when compiling Less files, excluding them from the build and just using the resulting css files).
another feature would be the easy way to add dependency's from the maven rep http://mvnrepository.com/

Intellij Java version

Can somebody tell me what are all the places where I have to change the java version, because I have changed it in more than 5 places so far (I don't even remember all of them) and it is still saying "diamond operator is not supported in -source 1.5". The most stupid ide ever..
Project -> Project SDK
Project -> Project language level
Modules -> Language level
Project bytecode version
Target bytecode version
If you use Maven in IntelliJ IDEA to build your project you have to set Java version as parameters source and target in configuration for maven-compiler-plugin:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Default version for this is 1.5 and IDE use it to check source code compatibility.

Does the POM file configuration overwrite the default settings of Spring Tool Suite configuration?

After checking this link No Compiler is provided in this environment
I observed that POM file configuration is overwriting STS default settings. This might be the reason whenever project is run on server, it is generating the error as mentioned in above link. This might be the code which is overwriting the STS default configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
This is a feature of the Maven support in Eclipse (which is also included in STS). It automatically maps your JDK version setting in your pom file to the compiler settings in Eclipse/STS. Otherwise you would end up having the IDE compile for a different JDK version than your Maven build - which would be a bit strange.

Issus with building the java project using maven2

I am using maven2 to build the java project, when i issue the command mvn clean install i am getting the error could not parse error message: (use -source 5 or higher to enable generics).
In my eclipse environment i am using jdk 1.7 and the project is working fine. when i want to build the project i am unable to do that, think maven is taking java version 1.3 as default.
Any one please help me how to set the jdk versio to 1.7 in maven, to build the project successfully..
Apart from the jars mentioned in pom.xml i want to add add my own jar, how can i specify that in pom xml?
Thanks in advance..
In your pom.xml configure the maven-compiler-plugin to use 1.6:
<build>
<plugins>
<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>
</plugins>
</build>

Maven confused about JRE been used

I've created a project in eclipse and added maven dependencies. In Eclipse, it says that I am using JRE 1.5. Everything works fine in Eclipse, for instance, I can run my tests.
When I try to run mvn clean install from the terminal, it gives me the following error.
...generics are not supported in -source 1.3 (use -source 5 or higher to enable generics)...
Its seems that Maven thinks I'm using JRE 1.3 and cannot recognize generics or for-each loops.
How can I:
Validate my assumption that maven is using the wrong version.
Get Maven to compile my project.
Specify the correct version of your JRE in the Maven compiler plugin, by default your pom.xml file will inherit the compiler-plugin from the Maven super pom.xml which targets the 1.3 JRE.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

Categories