How to create auto ssh login using Java?

I am trying to create a program for auto ssh login using Java. In linux, we have command expect to connect and interact with server. I found some
programs to work like expect command, and but getting some errors while compiling. Do anyone know better method to get expect like functions in Java ? Or anyone knows if there any other methods to achieve this ?
The following is the shell script that i am currently using for this

#!/usr/bin/expect -f
spawn  ssh -l $argv 0 $argv 1 -p $argv 3
expect "password:" { send "$SSHPr" } 
   "yes" {
            send "yesr"
            expect "password:"
            send "$argv 2r"
  expect "#" { interact } ">>" { interact 

It will login into the server and then we can interact with it.
Thanks in advance.