Switch java with direnv

direnv is a tool that allows you to switch environment variables for each directory, which is useful when you are developing multiple projects in parallel.

On Mac, if you define the following function in ~ / .direnvrc ...

# ~/.direnvrc
use_java() {
    if [ "$#" -ne 1 ]; then
    echo "usage: use java VERSION" >&2
    return 1
  fi
  local v
  v="$1"
  if [ "$v" -le "8" ]; then
    v="1.$v"
  fi
  export JAVA_HOME="$(/usr/libexec/java_home -v "$v")"
  PATH_add $JAVA_HOME/bin
}

For each project, just write like this

# [Project directory]/.envrc
use_java 11 #Use JDK 11

Note that direnv has a (subtly) useful feature that allows you to write ʻuse_hoge as ʻuse hoge, so you can also write this.

use java 11

For languages other than Java, ʻuse` is provided as standard.

https://github.com/direnv/direnv/blob/master/stdlib.sh https://github.com/direnv/direnv/blob/master/man/direnv-stdlib.1.md

Recommended Posts

Switch java with direnv
Seasonal display with Java switch
Java switch statement
Change seats with java
Install Java with Ansible
Easily switch Java versions with alias on macOS
Comfortable download with JAVA
Download Java with Ansible
Let's scrape with Java! !!
Build Java with Wercker
Switch versions with alternatives after yum install java
Endian conversion with JAVA
Easy BDD with (Java) Spectrum?
Use Lambda Layers with Java
Java multi-project creation with Gradle
Getting Started with Java Collection
Java Config with Spring MVC
Basic Authentication with Java 11 HttpClient
Let's experiment with Java inlining
Run batch with docker-compose with Java batch
[Template] MySQL connection with Java
Rewrite Java try-catch with Optional
Install Java 7 with Homebrew (cask)
[Java] JSON communication with jackson
Java to play with Function
Try DB connection with Java
[Java] JavaConfig with Static InnerClass
Try gRPC with Java, Maven
Let's operate Excel with Java! !!
Version control Java with SDKMAN
Java if and switch statements
RSA encryption / decryption with java 8
Paging PDF with Java + PDFBox.jar
Sort strings functionally with java
Object-oriented (java) with Strike Gundam
[Java] Content acquisition with HttpCliient
Java version control with jenv
Troubleshooting with Java Flight Recorder
Streamline Java testing with Spock
Connect to DB with Java
Connect to MySQL 8 with Java
Error when playing with java
Using Mapper with Java (Spring)
Java study memo 2 with Progate
Getting Started with Java Basics
Use SpatiaLite with Java / JDBC
Study Java with Progate Note 1
Compare Java 8 Optional with Swift
HTML parsing with JAVA (scraping)
Run Java VM with WebAssembly
Screen transition with swing, java
Java unit tests with Mockito
[Java 8] Duplicate deletion (& duplicate check) with Stream
Create an immutable class with JAVA
Java lambda expressions learned with Comparator
New grammar for Java 12 Switch statements
[Java, Scala] Image resizing with ImageIO
Build a Java project with Gradle
Install java with Ubuntu 16.04 based Docker
Morphological analysis in Java with Kuromoji
Use java with MSYS and Cygwin