Search code examples
javasshj2ssh

can I use two ssh java lib in my java code?


I am using j2ssh but due to some reasons (which we cant detect yet) we decided to switch to new ssh lib.

in j2ssh for 2 functions which are not giving expected result, we have to switch to new ssh (i have found vngx-jsch suitable)

but only for 2 functions, i need to do full rework of all ssh related function which i dont want to.
so I have following queries : -

  1. can I use both lib ?
  2. does it make sense ?
  3. what if I keep j2ssh as it is and only for those 2 function I will load vngx-ssh?
  4. is it possible?
  5. how to do it ? any example ?

Solution

  • Yes, It's possible. you can use the fully qualified names to resolve the conflicts. for example:

    let say there are 2 packages, com.package1.A and com.package2.B which exports the same function, func(). In your Java program, you can use any one of these by calling either

    package com.package1;
    
    public class A {
        public void func() {
           System.out.println("Inside A package's func ");
        }
    }
    

    And the second is:

    package com.package2;
    
    public class B {
        public void func() {
           System.out.println("Inside B package's func ");
        }
    }
    

    Then in a separate class you can use it like:

    public class App {
        public static void main(String[] args) {
            com.package1.A.func();
            com.package2.B.func();
    }
    }