Kevin's Blog

IT, Java, Web, Ubuntu

Tag: Java (page 1 of 9)

Trying Scala Script – Script to Create a Symbolic Link to JDK on Mac OS X

I used to use Ubuntu Linux most of the time, yet I’m using Mac OS X more these days. I’m quite satisfied with it, but there’s one thing inconvenient. That’s installing JDK. On Ubuntu, installing Java 8 (technically what I want to install is JDK 8 but since Java has really terrible versioning history, I’ll just call it Java 8) is not supported by Canonical, but it can be done easily by the PPA provided by Web Upd8 (Thanks Web Upd8).

On OS X, as we all know, PPA-like solution is Homebrew (hereinafter referred to as ‘brew’). I use brew to install Scala and SBT but there’s no brew formula for Java. So I need to download the JDK from Oracle’s Java website and install it manually or there is a brew-friendly alternative that is ‘Homebrew Cask’.

So I can simply do

There is still an issue though. Whenever a new version of JDK is installed, JAVA_HOME changes. Thus I need to change the location of JDK set in my IDE which is IntelliJ IDEA in my case. This is so annoying. The reason for using brew is to make things automated, yet in terms of JDK installation, it’s still so cumbersome. I partially solved it by creating a symbolic link to the JDK so that I don’t need to change the location set in IDEA when a new version of JDK is installed. Although it got rid of unnecessary JDK setup in IDEA, I do still need to change the link to the JDK. Still annoying. So I was thinking about writing a shell script to create a symbolic link to the JDK. Then, all of a sudden, I came up with writing Scala script. I can do it using Scala as a script language. I can simply add #!/usr/bin/env scala to the beginning of the shell script file which actually contains Scala code. Or installing scalas using Conscript might be another more powerful way as it gives me a way to use sbt in the script file (This case, #!/usr/bin/env scalas should be used instead of #!/usr/bin/env scala). I ended up using #!/usr/bin/env scala to avoid any extra installation.

It might be easier and better if some changes are made on brew cask Java formula to create the link. However, I’ve been working as a Scala developer for about three/four months so wanted to try Scala as a script language. Besides, I’m not a Ruby programmer. :) So here is the code.



See it on GitHub Gist

Click here to get the instructions to use it. <<==

I could have done a few things here using just Scala. For example, getting the list of directories, removing folder and so on. Yet, instead, I used ProcessBuilder as I wanted to use Scala to run OS processes. Just to try something I don’t usually do although I’ve done it before in Java in order to manipulate images using ImageMagick and to render HTML info PDF using wkhtmltopdf.

When running it, a result would be like this. (For more details, Click here!)

Java 8 – Lambda Expressions, Method References and Default Methods

Java 8 – Lambda Expressions, Method References and Default Methods

More information will be added later.

1 / 9: Lambda Expressions? (Click to watch)

2 / 9: Details of Lambda Expressions

3 / 9: Closure

4 / 9: Method References

5 / 9: Default Methods

6 / 9: First Class Functions

7 / 9: Target Type Inference

8 / 9: Stream API
Coming soon…

9 / 9: Examples
Coming soon…

Kevin’s Projects

My Projects:

This one is my project page.
http://lckymn.com/kevin-projects
 
 

About Me:

‘About Kevin’ page’s been moved to
http://lckymn.com/about-kevin
 
 

Older posts

© 2015 Kevin's Blog

Theme by Anders NorenUp ↑

%d bloggers like this: