Issus with building the java project using maven2 - java

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>

Related

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.

Compile errors with Maven but not in Eclipse after upgrade from java 1.7 to 1.8

I am aware that similar questions has been asked in the past, but I couldn't found my answer in it.
I am using Eclipse Luna and upgraded to java 8 (build 0.25).
The JAVA_HOME points to java 8 and also it's part of the Windows Classpath.
After the upgrade, maven compile shows some Ambiguous method calls that didn't show up in java 7.
The problem is that these errors aren't shown in Eclipse and I can't find why.
I removed all jre's in eclipse and removed/added the java 8 jdk, but still no luck.
Also Eclipse is using the java 8 environment for compiler errors/warnings.
With maven I use the "plexus-compiler-javac" compiler, snapshot 2-4. I also tried without the plexus compiler and with version 2.0, but no luck.
Any idea what this could be?
My Pom snippet:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<!--version>2.0</version-->
<version>2.4-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<verbose>true</verbose>
<source>1.8</source>
<target>1.8</target>
<fork>false</fork>
<encoding>utf-8</encoding>
<meminitial>256m</meminitial>
<maxmem>1024m</maxmem>
</configuration>
</plugin>
Try telling maven to use java 8 source level by adding/changing configuration of your compile plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
i face this issue with tools.jar not found, so download the latest tools.jar & copy to D:\Java\jdk1.8.0_25..\lib\tools.jar, thanks.

Maven can't change the library set by default

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.

Java/Maven compilation failure (no suitable constructor found)

I ran into a strange problem..
I work on a project that use the ProcessBuilder Class.
On my local machine (Java6 and Java7 tested) I can easily mvn clean install & mvn assembly:single the project without any errors. Now I want to let the project build by travis-ci and ran into to following error
error: no suitable constructor found for ProcessBuilder(String)
full log file here..
but the Javadoc for ProcessBuilder show me that constructor.
My .travis.yml looks like this
language: java
jdk:
- oraclejdk7
- openjdk6
- openjdk7
after_success:
- mvn assembly:single
Any ideas why the build fails on travis-ci?
Thanks, F481
Edit:
Locally I'm using Maven 3, like travis-ci too (travis doc: "Travis Java builder will use Maven 3 to build it.")
My pom.xml: https://github.com/MultiServerControl/MineControl/blob/master/pom.xml
And the java code of the first error: this.processBuilder = new ProcessBuilder("");
The full class is available here
Edit2:
I specified a source and target version for the maven compilation like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Now the build is working for JDK7: https://travis-ci.org/MultiServerControl/MineControl/jobs/5963859
But I don't get the reason for that behavior.. and I want to build the project for JDK 5,6 too.
How can I do that?
I specified the version of the maven compiler plugin and the source and target version for the compilation like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Now the build is working! Much thanks to NilsH who pushed me in the right direction.

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