Why does Maven use the wrong JDK version when running from Fish? - java

I run macOS Sierra, and have installed the Fish shell (https://fishshell.com/).
When I try to build a Maven project, it now gives me
Fatal error compiling: invalid target release: 1.8 ->
... which means that it has picked up an older JDK which it tries to use to build my Java 8 project with.
This is made obvious by running mvn -version:
...
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
...
But I have JAVA_HOME set correctly, echo $JAVA_HOME in both shells give me:
/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
and java -version gives me
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
and javac -version:
javac 1.8.0_112
echo $PATHgives the same result in both shells (except that in Bash, the directories are separated by :; in Fish, a space ):
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin
I have configured maven-compiler-plugin to for 1.8:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
Why does Maven insist on using the 1.6 JDK? The same project builds fine, with the correct 1.8 JDK, when running through Bash.

If you are running an old version of maven, please try updating to the latest version (3.5.0), e.g. via homebrew (brew install maven).

Related

Not able to run Junit test cases in IntelliJ version : community 2017.2, error : Information:java: Errors occurred while compiling module 'XXXXX'

Not able to run Junit test cases in IntelliJ version : community 2017.2, same was working fine with old versions.
I have found two links link1 and link2 but not able to resolve the issue. Please help.
Error I am getting :
Information:java: Errors occurred while compiling module 'XXXXX'
Information:javac 7 was used to compile java sources
Information:18/10/17, 1:10 PM - Compilation completed with 1 error and 0 warnings in 2m 11s 343ms
Error:java: Compilation failed: internal java compiler error
The pom.xml has,
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Project gradle version
$ gradle -version
------------------------------------------------------------
Gradle 3.0
------------------------------------------------------------
Build time: 2016-08-15 13:15:01 UTC
Revision: ad76ba00f59ecb287bd3c037bd25fc3df13ca558
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_80-ea (Oracle Corporation 24.80-b07)
OS: Mac OS X 10.12.6 x86_64
Thanks in advance.

Minify Maven Plugin throwing "JavaScript engine not supported" error

How can I configure the Minify Maven Plugin plugin to work with Maven 2.2.1 while also using the Google Closure Compiler?
According to this issue, Version 1.7.1 should work with that particular version of Maven, but on minification, it is throwing this warning: "[WARNING] JavaScript engine not supported". The concatenation of the bundles works as expected. I am upgrading from version 1.2.4 to the utilize the the Closure Compiler. I need Closure Compiler as YUI has some unresolved bugs with certain ES2015 syntax. We won't be upgrading to Maven 3 for a while.
workstation details:
java version "1.8.0_60"
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java version: 1.8.0_60
OS name: "mac os x" version: "10.10.4" arch: "x86_64" Family: "mac"
My configuration:
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<id>someBundle</id>
<phase>process-classes</phase>
<configuration>
<webappSourceDir>web/src/static${static.asset.basedir}</webappSourceDir>
<webappTargetDir>web/target/minify</webappTargetDir>
<jsSourceFiles>
<param>libs/somelib.js</param>
<param>libs/anotherlib.js</param>
</jsSourceFiles>
<jsFinalFile>bundle.js</jsFinalFile>
<jsEngine>CLOSURE</jsEngine>
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
</plugin>
This question was pretty obscure so I'll answer it by posting my solution. I was fearful that upgrading to Maven 3 would open up a can of worms, but it didn't. As a matter of fact, it just worked after changing the location of the Maven home directory (in IntelliJ and in the zsh profile - M2_HOME) and the location of our Maven Repository (which was not in the default location). I build with both IntelliJ and by command line so both locations needed to be updated.
New home directory location (installed with Homebrew):
/usr/local/Cellar/maven/3.3.3/libexec
Local Maven repository setting updated in this file:
/usr/local/Cellar/maven/3.3.3/libexec/conf/settings.xml
Update this value:
<localRepository>/path/to/local/maven/repository/</localRepository>

Maven Compilation Error: Fatal error compiling: invalid target release: 1.8

Similar problem as posted in Fatal error compiling: invalid target release: 1.8 -> [Help 1]
However, problem is not solved after I check my settings with the solutions. Details is as follows.
Maven Error Message is:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
My JAVA_HOME setting is:
C:\Program Files\Java\jdk1.8.0_40
Java -version:
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
I've added compilation detail to pom.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
As discussed in comments, You need to restart your console after setting your %JAVA_HOME% enviroment variable.
Eclipse Users, Cross check your run configuration in Maven build. Follow steps to correct -
"Run Configuration"
Under "Maven Build", Select configuration you are using
Click on "JRE" tab
Select Correct JAVA Version
This solution works for me!

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 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