mvn invalid target release: 1.7 - java

mvn test :
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project vslimit: Fatal error compiling: invalid target release: 1.7.0_65
pom:
<java-version>1.7</java-version>
`<plugin>`
`<groupId>org.apache.maven.plugins</groupId>`
`<artifactId>maven-compiler-plugin</artifactId>`
`<version>3.2</version>`
`<configuration>`
`<source>${java.version}</source>`
`<target>${java.version}</target>`
`<encoding>${project.build.sourceEncoding}</encoding>`
`</configuration>`
`</plugin>`
java -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
mvn -v
Apache Maven 3.2.1 Maven home:
/Users/vslimit/tool/apache-maven-3.2.1 Java version: 1.7.0_65, vendor:
Oracle Corporation Java home:
/Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home/jre
Default locale: platform encoding: UTF-8 OS name: "mac os x",
version: "10.10.2", arch: "x86_64", family: "mac"
i has try a lot of suggests,ex:java_home or other,but failed

change your pom.xml to have
<project>
...
<properties>
<java.version>1.7</java.version>
</properties>
...
</project>

Related

Different result maven and jdk 1.7 vs jdk 1.8

I have a maven module and I have this situation:
if I compile the module with jdk 1.7 it will create a jar file and a 'META-INF' folder. But it does not include classes from the module, so in runtime I get the ClassNotFoundException.
but, if I compile the same module with jdk 1.8, classes are added to the jar file.
I'll attach a photo to see the result.
I use maven to compile (from terminal, not ide).
This is maven info: Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: C:\development\apache\apache-maven-3.6.3\bin.. Java version: 1.7.0_80, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.7.0_80\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"
And this is java info: java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode) and Java 1.7.0_80 and this is an example of a pom.xml.
And this a pom example:
hermes-maven-plugins
hermes
4.3-SNAPSHOT
<modelVersion>4.0.0</modelVersion>
<artifactId>hermes-css-generator-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>css-generator Maven Mojo</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>hermes-front</groupId>
<artifactId>hermes-front-commons</artifactId>
<version>${hermes.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
None of the classes I have in module hermes-front are included in the compiled jar. But using java 8 I do have all this files included in jar. Java 8 info is:
java version "1.8.0_231" Java(TM) SE Runtime Environment (build 1.8.0_231-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
Does anyone has an idea why this could happen?
I need to use the jdk 1.7 version until this jdk is updated in pro environment.
Thanx a lot.
enter image description here

How I can override charset in Maven?

if I run my java maven project from Eclipse I don't habe problems. All encodings are UFT-8, but if I compile with
maven clean package
I have problems with the encoding on some different places. XSLT-transform, SOAP and so on.
I found some tricks in the Internet, but nothing helps. What can I do?
Things I tested with no effect:
pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>
On console:
mvn -DargLine=-Dfile.encoding=UTF-8 clean package
$ mvn --version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T20:49:05+01:00)
Maven home: C:\Program Files\apache-maven-3.5.3
Java version: 1.8.0_201, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_201\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
The Platform encoding is CP1252.
How can I say maven to use UTF-8, Eclipse can do it.
Thanks for any help.
UPDATE:
I enabled the DEBUG output from Eclipse, there are this lines:
Maven home: C:\Users\EMBEDDED
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_201\jre
Default locale: de_DE, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
platform encoding: UTF-8 <- How can I do this
UPDATE 2:
Setting Systemvariable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8 helps. Now it works.

javac: invalid target release: 1.8 on Mac when executing Maven command

I am trying to run automation test on Mac. I installed Maven and java, jdk as following:
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
and Maven:
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T18:29:23+01:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"
When I executed Maven command, I got this error:
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.8
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
[ERROR] -> [Help 1]
I searched on here, there's one accepted solution is this:
sudo cp $JAVA_HOME/lib/tools.jar /Library/Java/Extensions/
I executed this command, but nothing happened! I don't know what's wrong.
First, figure out where 1.8 Java is installed by running the command:
/usr/libexec/java_home -v 1.8
Then, set your JAVA_HOME environment variable by running the command:
export JAVA_HOME=<whatever the output from the previous command was>
Maven should work afterwards, at least in that terminal window.
You'll have to set the JAVA_HOME environment variable in your profile if you don't want to have to run these commands every time you open a new terminal.
If you haven't done so already, use the maven-compiler-plugin to determine the Java version to use within Maven. Put this in your pom.xml file (change the <source/> and <target/> version to the JDK version you require):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
(If you already have a <build/> and/or <plugins/> section, add the <plugin/> portion, only.)

Maven compilation error. Failure executing javac, but could not parse the error:javac: invalid flag: -s

I am getting a compilation error when try to execute mvn clean install.
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid flag: -s
Usage: javac <options> <source files>
Java version is
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode, sharing)
Maven version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: C:\Sajith\apache-maven-3.0.3\apache-maven-3.0.3
Java version: 1.5.0_16, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.5.0_16\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.sample</groupId>
<artifactId>TestApp</artifactId>
<description>TestApp Release 1.0 Build</description>
<version>2.0</version>
<packaging>pom</packaging>
<name>TestApp API</name>
<url>http://maven.apache.org</url>
Any help would be appreciated.
The problem is that your maven is using java 5 (as your comment says). You have to change your JAVA_HOME variable to point to jdk 6 or higher. Look at :
Error when using javac: "javac: invalid flag: -s"
In my case i dont have the apropiate environment variable because the project is inherited, and I had not created the variable JDK_WAS85_JDK8 = C:\Program Files\Java\jdk1.8.0_221.
Usually is JAVA_HOME the variable that is set.

Maven doesnt use specified source and target settings

I'm trying to build a java project using maven. In the pom.xml file at the root of the project I have the following lines:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<debug>true</debug>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
but when I try to build with mvn -DskipTests -U install, I get the following error: static import declarations are not supported in -source 1.3
maven is not using the source and target (1.6) that i've specified in the pom.
java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
mvn --version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-21-generic", arch: "amd64", family: "unix"
uname -a
Linux ubuntu 3.5.0-21-generic #32-Ubuntu SMP Tue Dec 11 18:51:59 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Is there anywhere else that maven might be getting its default source and target settings from? Why isnt it using the settings from the pom?
Here is a snippet of error message when maven is ran in debug mode:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project LeaderLines: Compilation failure
[ERROR] /path/geoserver-2.2/geotools-plugin/LeaderLines/src/org/geotools/filter/function/FilterFunction_leaderLine.java:[22,7] error: static import declarations are not supported in -source 1.3
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins: maven-compiler-plugin:2.0.2:compile (default-compile) on project LeaderLines: Compilation failure
/path/geoserver-2.2/geotools-plugin/LeaderLines/src/org/geotools/filter/function/FilterFunction_leaderLine.java:[22,7] error: static import declarations are not supported in -source 1.3
Try setting the source level and source encoding with the following properties:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Try to clear you local Maven repo and run your build again (maybe, try also to run it with '-o' option)

Categories

Resources