0

I have two projects on my computer that require JAVA_HOME to point to jdk7 and 8 respectively.

Right now I'm working around this by having 2 files in my home folder that i source to set JAVA_HOME correctly whenever I move to the root folder of one of these folders.

Is there a way I can tie the sourcing of these files to the action of "cd"ing to the root of these projects?

1
  • To start the jar/class file in this folders or to develop the projects?
    – A.B.
    Aug 21, 2015 at 10:59

1 Answer 1

1

If using the bash shell, add to your .bash_profile:

mycd(){
        builtin cd "$@"
        case $PWD in
        */proj1*)  export JAVA_HOME=/a ;;
        */proj2*)  export JAVA_HOME=/b ;;
        esac
}
alias cd=mycd

Then when you type cd ... it will run mycd in which you can do stuff. It starts by calling the real built-in cd.

You need to start a new interactive bash to see the effect, of course.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .