Menu bars

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 18 June 2017

Building a Spring boot application in Ubuntu 16.04 using gradle and Running a headless chrome from selenium

Hello everyone, this is my side by side blog on how to build my spring boot application in Ubuntu 16.04. I have already a project with basic spring boot specification which has build using gradle. This is my learning project on gradle and spring boot. So we all need a unix based os for deploying these to a cloud based hosting like digital ocean. So lets start.

These are the steps that i have already done.
1. Installed gradle in ubuntu 16.04 by following this article.
2. Copy the spring boot project to ubuntu box.
3. Installed Mongodb on Ubuntu machine by following this article
4. Installed Java 1.8

Oh.. Gradle !! Yeah it is a build automation tool that will take care of all the dependency and build tasks that we need to do while creating a project. Of course you can use other build tools like Maven,ant etc. But gradle comes with more power that other build tools in java.

Heard about gradlew ? It is worth looking into this if you are using gradle which will reduce your headache of installing gradle and will escape you from the version mismatch drama. Gradle vs gradlew ? . Gradle wrapper command will create gradlew.

Ok. lets come back to our Ubuntu Box. Our objective is to run spring boot in Ubuntu machine and the boot application is having a dependency on mongodb services. So we need to setup that as well.

You just need to go to the root directory where the build.gradle file exist and execute the command gradle bootRun. This will launch the spring boot process and you will something like below.


Yay !! spring boot has started !!.

One of my requirement for this spring boot project is that i want to run a selenium scrapper from this project that too headlessly using chrome. This link provides you more information on how can you install headless selenium.

Luckily Chrome has rolled out chrome-59 with headless feature which we can use for our experiment. Get the latest version of the chrome from this link.

So  i have installed google-chrome 59 and all ready for running my headless chrome instance with selenium with spring boot. I have tested my application code in my windows machine and it worked like a charm. Now i am testing it on my Ubuntu server. fingers crossed !

It throws me unable to start exception. Mostly its because Ubuntu server is not able to start it on a graphical way. Lets investigate.


woo.. after a long 3-4 hours i could run the chrome 59 headless from selenium. Initially i was getting the same above error whatever i changed. I did a lot of googling to find out why the same exception coming. It was due to one of my big blunder of adding the wrong system property. I was adding the actual chrome installation path in the webdriver.chrome.driver property. Everything started working once i replaced the same with chrome-driver location.

For that i have downloaded the chrome-driver from the Chromium.org download site. And i did something similar including the symlink like this.

This particular script written in Github shows all the steps that we need to do to install the Chrome+selenium combo in your Unix boxes.

So here is my complete java code that running the selenium which invoke the headless google-chrome in Ubuntu machine.


And we need to pass the extra arguments for running the chrome in headless mode(Note that this feature available only google-chrome-59 onwards). The versions of the applications that used as follows.

Java - 1.8
Selenium - 3.*
google-chrome - 59
chromeDriver - 2.3

That's it guys. We have successfully ran our spring boot application which can invoke chrome instance headless way from selenium. Tune in for more. Thanks a lot.  

Sunday, 30 April 2017

Pointers for Spring boot + Mongodb applications

Connecting the mongodb database to spring boot is very important and powerful. The most easy way to persist your application data is to store it somewhere. We all do it by storing it into some kind of databases. In these types of databases i found out that mongodb is very easy to handle and configure as it is schema-less. So i dont need to create any sort of database design instead i can send my json file for saving it and i can retrieve it back.

First of all, lets look into some basic links that needed.

1a. Install mongodb on ubuntu 16.04 - Link
1b. Install mongodb on windows 7 -  Link

2. You can use mongo command to see the CLI of mongo instance that is running, a few basic         commands as follows.
    - show dbs
    - show collections
    - db.{collection_name}.find()

If you want to understand how MongoDB can be used in spring boot then this link will give you a good idea to do it.  In this article you can see that there are two types of connection that can be used to connect to mongodb and i found out that mongotemplate is having much more flexibility.

More complex mongoTemplate queries can be made by following this article.


============================== References==================================
It is a good starting point for starting spring boot applications. It follows very good design patterns to follow. Check here

You might also need to get some of the annotations that are needs to be used. check this