Vbox (001): Mounting shared folder

To access the host filesystem do the following:

Create a machine-level shared folder:

  • Menu Shared Folders
  • Give it a name, eg ‘Share’
  • Point to the correct directory, eg ‘C:\Users\Dev01’ on windows
  • Check make permanent
  • OK

Mount the shared folder in the host

Now in the guest open the terminal and type:

Your host drive is now accessible thru /mnt/hostshare

Gradle (002): Getting started

Let’s create a very simple Gradle java project. Make sure Gradle is installed. See this link. Also java must be installed.

Create the Project folder:
devbox$ cd ~/Development/projects
devbox$ mkdir FirstGradle
devbox$ cd FirstGradle
devbox$ mkdir -p src/main/java/demo

Create the class and add some code
devbox$ vi src/main/java/demo/HelloGradle.java
:i (insert text)
1 package demo;
2
3 public class HelloGradle{
4 public static void main(String[] args) {
5 System.out.println("Hi Gradle!");
6 }
7 }
:x (save and close)

Now create a basic build file
devbox$ vi build.gradle
:i (insert text)
1 apply plugin: 'java'
:x (save and close)

Next we comple the code. Note that we are still in ~/Development/projects/FirstGradle.
devbox$ gradle build

We can list the folders created by Gradle on the mac using this command:
devbox$ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

The jar is stored in ./build/libs/ The file isn’t usable yet. If you run it you get a error because no Main method is found.
devbox$ java -jar build/libs/FirstGradle.jar

We need to add something to the gradle.build file to make sure the manifest is created.
apply plugin: 'java'

jar {
manifest {
attributes ‘Main-Class’: ‘demo.HelloGradle’
}
}

Now rebuild and run the example.
devbox$ gradle build
devbox$ java -jar build/libs/FirstGradle.jar

Gradle (001): Download Gradle and install

We will download and install gradle on Mac OSX Sierra. Replace commands below with more recent version numbers.

Download the software:
devbox$ cd ~/Development/software
devbox$ curl -O https://services.gradle.org/distributions/gradle-3.5-all.zip
devbox$ ls -la

Whoops. The downloaded file is empty. What happened? Let’s see what the HTTP response tells us (-I option).
devbox$ curl -I https://services.gradle.org/distributions/gradle-3.5-all.zip

The response is of type 301 (Moved permantly). Now let’s add the -L flag to follow redirects.
devbox$ curl -LI https://services.gradle.org/distributions/gradle-3.5-all.zip

That looks better. It does still get the 301, but then follows until the 200 (OK). So try again without -I and output the file to disk (-O).
devbox$ curl -LO https://services.gradle.org/distributions/gradle-3.5-all.zip

Unzip the file and install in path like we did for Maven:
devbox$ unzip gradle-3.5-all.zip
devbox$ echo 'PATH=$PATH:~/Development/software/gradle-3.5/bin' >> ~/.bash_profile
devbox$ source ~/.bash_profile

Test our installation:
devbox$ gradle -version

Devbox (002): Download Maven with MD5 check and install.

We will download and install maven on Mac. Replace commands below with more recent version numbers. During this operation we will also check the md5 hash to check if our download is the same as the file on the server. We will also learn how to untar a file unix style.

Download the software:
devbox$ cd ~/Development/software
devbox$ curl -O http://www-eu.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz

Download the checksum from maven:
devbox$ curl -O https://www.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz.md5

Generate your own checksum against the downloaded file:
md5 -q apache-maven-3.5.0-bin.tar.gz > my-checksum.md5

Compare the two md5 hashes. If they are the same we know the downloaded file is not malformed during download. The -w option is to ignore any whitespaces (also newlines and tabs) during comparison. This is needed in this case because my md5 ends with a newline while maven’s md5 doesn’t and that would break the diff. No result running diff? That’s a good thing.
diff -w my-checksum.md5 apache-maven-3.5.0-bin.tar.gz.md5

Now let’s un-tar.
devbox$ tar xvzf apache-maven-3.5.0-bin.tar.gz
x -> Output to disk
v -> Verbose output (see output of what it is doing)
z -> Decompress
f -> Filename

The new un-tarred filename is apache-maven-3.5.0. This isn’t very easy to use. So let’s rename it and also clear the downloads.
devbox$ mv apache-maven-3.5.0 mvn
devbox$ rm apache-maven-3.5.0-bin.tar.gz
devbox$ rm apache-maven-3.5.0-bin.tar.gz.md5
devbox$ rm my-checksum.md5

Finally, mvn must be visible outside ~/Development/software/mvn. To do so we add this to the path variable. The fastest way is to redefine the PATH at the end of .bash_profile. The following command does that and will even create the file if it doesn’t exist. The source command is used to reload the file so we can use it right away.
devbox$ echo 'PATH=$PATH:~/Development/software/mvn/bin' >> ~/.bash_profile
devbox$ source ~/.bash_profile

Now let’s test. This should output the version we are using, but also the home directory where we’ve installed maven. Verify to see we are not being overruled by another installation.
devbox$ mvn -version

Voila.