Sunday, October 9, 2022

Auto-Reload Spring MVC Project

This is a much-required process while we develop spring boot applications. We do changes continuously and want to see the result at the same time without manually rebuilding the application. 

For the changes in Java files, we need to include a dependency 

developmentOnly 'org.springframework.boot:spring-boot-devtools'


In Eclipse, this should be enough, I have not tested it though.

If you are using IntelliJ, we need to do one extra step to enable hot-reload.





You need to go to settings (CTRL+ALT+S) and click "Build, Execution, Deployment" select "Compiler", and then on the right side, select the select "Build project automatically".


So far, we have implemented the hot reload of Java files. 

This does not take care of the changes in other files, for example, changes in template files, or other resources files. There are many alternatives to implement this, I prefer using gulp which watches the changes in the resource files and transfers the changes files into the build directory.  

(Reference:https: //attacomsian.com/blog/spring-boot-auto-reload-thymeleaf-templates )

1) Your system should have the latest npm and node. 
2) Instal gulp-client 
npm install gulp-cli -g
Installing globally makes it available to all other applications too.
3) Create a file package.json in the root folder with the following content

{
"name": "Corona Tracker",
"scripts": {
"gulp-watch": "gulp-watch"
},
"dependencies": {
"gulp": "^4.0.2",
"gulp-watch": "^5.0.1"
}
}


4) Run the command npm install (which installs these packages) 
5) Now, we have to define the actual task of watching and taking action. For that, create a file called "gulpfile.js" with the following text:

var gulp =require('gulp'),
watch=require('gulp-watch');

gulp.task('watch',function(){
return watch('src/main/resources/templates/**/*.*',()=>{
gulp.src('src/main/resources/templates/**')
.pipe(gulp.dest('build/resources/main/templates/'));
});
});

The task defined here is "watch"

6) Run "gulp watch" which watches directory templates, and if any changes are there, it copies the changes into the build directory. 


I preferred this method of loading static file changes because it is fast and fully customizable. The method in IntelliJ did not work in my case. (Changing IntelliJ registry did not sound good to me) 

Monday, September 19, 2022

Access Systems in a LAN in Windows 10

Accessing a remote system with a hostname is a bit tricky in windows 10. I went on forgetting after it is done, so writing it as a reference.

It is very easy to map remote ip with a hostname. 

The file is located under

C:\Windows\System32\drivers\etc\hosts

You need to be an administrator or open notepad to change the file. 

In this file, you just need to type ip address of the remote system and the hostname to access it. 

Thats it !

Sunday, February 27, 2022

Scala 3 Introduction

Scala3 is trending and it's a significant upgrade from scala2. In this article, I am going to write a short introduction to what actually does Scala do and how can we start programming with it. I have done some research on the recently released version (called Scala3) and how can we get started with it. 

Preparing Environment

To prepare the development environment for scala, we have to install java, scala, and configure the JAVA_HOME path so that scala knows where the java is installed. The use of sdkman makes the task of managing the SDKs easier, I prefer to install it. 

1) Install SDKMan

The installation of sdkman is simple. Go to this URL and follow the instructions


Commands:
Installation
$ curl -s "https://get.sdkman.io" | bash
Load Environment
source "$HOME/.sdkman/bin/sdkman-init.sh"
Test it 
$ sdk version

2) Install JDK
$ sdk install java

3) Install Scala

$ sdk install scala

4) Install SBT

$ sdk install sbt

You can verify the installation from the command line. 


Create a sample Scala3 project:
sbt new scala/scala3.g8
This will create a sample Scala3 project. We can take this to start a project.