jdeps command

David DeHaven david.dehaven at oracle.com
Wed Apr 29 21:41:42 UTC 2015


> It was suggested on the jigsaw-dev list that I raise this issue here.
> The jeps command appears to have no /usr/bin symlink.
> 
> which jdeps
> /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/jdeps
> 
> I believe this command was introduced with JDK 8.
> 
> One thing that I considered a minor issue is that this misses the JDK 9 early access I have installed.
> 
> It was indicated by Mandy Chung on the jigsaw-dev list that...
>> /usr/bin/j* are linked to
>> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands
>> probably part of OS install and I guess it's a snapshot of JDK 7
>> commands.
> 
> If this is true, ‘part of OS install’, I would guess they may not of even been updated for JDK 7, and no new Java commands from Java 6 on will ever have OS X /usr/bin links going forward.

We had one added for jmc, IIRC that's the last tool we've requested. The issue with the stub Java tools in /usr/bin is they're maintained by Apple, so if we add or remove tools it gets out of sync and worse yet is entirely dependent on when or even IF Apple releases a Java update for that particular OS version, which on older systems is not guaranteed to happen.


My solution is to put this in ~/.profile and skip using the stub tools in /usr/bin:
--- cut here ---
# add to front of path
prepend_path() {
  if ! eval test -z "\"\${$1##*:$2:*}\"" -o -z "\"\${$1%%*:$2}\"" -o -z "\"\${$1##$2:*}\"" -o -z "\"\${$1##$2}\"" ; then
    eval "$1=$2:\$$1"
  fi
}

export JDK_HOME=`/usr/libexec/java_home -v 1.8`
prepend_path PATH "${JDK_HOME}/bin"
--- cut here ---

Prepending it overrides the stub tools in /usr/bin. You're free to set whatever path you want for JDK_HOME, but if you use java_home then you don't have to manually juggle links or variables to track it.


This also allows javapackager to be run without scraping up a path first :)


Using PATH tools, you can change which JDK you use on the fly:
--- cut here ---
# add to front of path
prepend_path() {
  if ! eval test -z "\"\${$1##*:$2:*}\"" -o -z "\"\${$1%%*:$2}\"" -o -z "\"\${$1##$2:*}\"" -o -z "\"\${$1##$2}\"" ; then
    eval "$1=$2:\$$1"
  fi
}

# removes a path
remove_path() {
  eval "$1=$(eval echo \$$1 | tr -s ":" "\n" | grep -vwE "($2)" | tr -s "\n" ":" | sed "s/:$//")"
}

# check if the given dir is already in the path, returns 1 or 0
check_path() {
  test `echo $PATH | grep --quiet -v "$1"`
}

# JDK path functions
switch_jdk() {
  NEW_JDK_HOME=$1
  test -d "${NEW_JDK_HOME}/bin" || {
    echo "Invalid JDK path"
    return
  }

  check_path "${NEW_JDK_HOME}/bin" && return

  test -n "${JDK_HOME}" && {
    remove_path PATH "${JDK_HOME}/bin"
  }

  eval JDK_HOME="${NEW_JDK_HOME}"
  prepend_path PATH "${JDK_HOME}/bin"
}

find_jdk() {
  # usage: find_jdk <version>
  FOO=`/usr/libexec/java_home -F -v $1 2>/dev/null`
  test -z "$FOO" && {
    echo "No JDK for version $1 found."
    return
  }
  switch_jdk "$FOO"
}

# default to the latest JDK 8
find_jdk 1.8

--- cut here ---


-DrD-



More information about the macosx-port-dev mailing list