user2148736
user2148736

Reputation: 1323

Maven uses later version of Java

I installed Maven via Homebrew:

brew install maven

everything went ok, but when I ask for Maven version, there is a notice that Maven uses older version of Java:

macbook:~ jirka$ mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 17:22:22+0200)
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: cs_CZ, platform encoding: MacCentralEurope
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"

but I use Java 7 for developing and version 7 is used in all system:

macbook:~ jirka$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
macbook:~ jirka$ 

I would like to ask you, is this a problem that a Maven uses later version of Java? Is there some consequences between Java version used by Maven and fact that applications are written for Java 7?

EDIT - my system setting:

macbook:~ jirka$ env
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/tx/c11w5sf11zj6qbfh5skp8kx00000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-85UUQ1/Render
TERM_PROGRAM_VERSION=326
TERM_SESSION_ID=AA674B2A-E20C-4B7F-BCD3-8DE637363A00
USER=jirka
SSH_AUTH_SOCK=/tmp/launch-XIC65i/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:29:56
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin
__CHECKFIX1436934=1
PWD=/Users/jirka
LANG=cs_CZ.UTF-8
SHLVL=1
HOME=/Users/jirka
LOGNAME=jirka
_=/usr/bin/env
macbook:~ jirka$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin
macbook:~ jirka$ echo $JAVA_HOME

macbook:~ jirka$

Upvotes: 0

Views: 1781

Answers (3)

MariuszS
MariuszS

Reputation: 31567

Try to fix your development environment with jenv.

jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable

brew install https://raw.github.com/gcuisinier/jenv/homebrew/jenv.rb

jenv add /Library/Java/JavaVirtualMachines/jdk17011.jdk/Contents/Home oracle64-1.7.0.11 added

jenv global oracle64-1.7.0.11

Upvotes: 1

user2148736
user2148736

Reputation: 1323

There is a need to set JAVA_HOME system variable via export command:

macbook:~ jirka$ cat '.bash_profile' 
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

Upvotes: 0

Ernestas Kardzys
Ernestas Kardzys

Reputation: 1727

Well as far as I can tell from my experience you might encounter some problems with Java 7 for development and with Java 6 for Maven. For example you can use some specific features of Java 7 (like try-with-resources statement) which are not supported in Java 6.

Try entering in your console:

echo $PATH

echo $JAVA_HOME

$PATH is probably pointing to Java 7, while $JAVA_HOME is pointing to Java 6. If it's your case - edit your $JAVA_HOME and make it point to your Java 7 installation.

Upvotes: 1

Related Questions