Monday, April 18, 2022

sample docker file for JAVA application

 You can add following Dockerfile to JAVA docker image.

#Use open JDK 8 image as the base image
FROM openjdk:8

#Create a new app directory for my application files (Inside image file system)
RUN mkdir /app

#Set the directory for excuting future commands
WORKDIR /app

#Copy my application files from host machine into image file system
COPY target/docker-helloworld-1.0-SNAPSHOT.jar  app.jar

#Run jar file
ENTRYPOINT ["java","-jar","app.jar"]
#CMD java -jar app.jar

docker commands

  • docker -version

checking current installed docker version

  • docker container run hello-world

run hello-world docker image. if image is not available in local repository, above command will download the image from docker-hub

  • docker run -it ubuntu bash
run ubuntu container in docker.
  • docker ps
list running docker container
  • docker image  build -t hello-world:1.0 .
use above command for buid a docker image. (here . means Dockerfile contains in the current directory)
  • docker container run hello-world:1.0
use below command for run above docker image.
  • docker image ls
list images in local repository

Wednesday, March 23, 2022

Shutdown Spring Boot Command Line Application

You can use ConfigurableApplicationContext to shutdown/closes all resources used by application as follows.

 public static void main(String[] args) {

        ConfigurableApplicationContext ctx=SpringApplication.run(Application.class, args);

        ctx.close();

    } 

    @Bean

    public CommandLineRunner commandLineRunner(RestTemplate restTemplate) {

        return args -> {

}

    }


Monday, March 14, 2022

Remove the <return> tag from SOAP response in JAVA

 Following JAVA annotation can be used to avoid <return> tag from SOAP web service response.

@WebService(serviceName = "Operations")

public class Service {

    @WebMethod(operationName = "processUser")

    @SOAPBinding(parameterStyle=ParameterStyle.BARE)

    public Result processUser(@WebParam(name = "userName")String userName) {

        Result result = new Result();

        result.setResultCode("1");

        result.setResultDesc("success");

        return result;

    }

}

ParameterStyle.BARE will return SOAP response with your defined object attributes.


Tuesday, November 23, 2021

List directories with sizes in Linux

du -sh *

Above command can be used to grep directory sizes in Linux. Go to required directory and execute above command.

Thursday, August 26, 2021

JSCH "Algorithm negotiation fail" error

It was received the following error when creating SSH session using JSCH client. I was able to resolve this after updating JSCH version to 0.1.54.

com.jcraft.jsch.JSchException: Algorithm negotiation fail

        at com.jcraft.jsch.Session.receive_kexinit(Session.java:583)

        at com.jcraft.jsch.Session.connect(Session.java:320)

        at com.jcraft.jsch.Session.connect(Session.java:183)

<!-- https://mvnrepository.com/artifact/com.jcraft/jsch -->
<dependency>
    <groupId>com.jcraft</groupId>
    <artifactId>jsch</artifactId>
    <version>0.1.54</version>
</dependency>

Saturday, July 17, 2021

Kill processes created under specific user in Linux

 You can use following commands to kill processes created under specific user in Linux.

for k in `ps -ef | grep usr01| grep ssh | awk '{print $2}'` ; do kill -9 $k ; done

Here, it is killing ssh sessions created by usr01 user.