0

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 ?
Vinay Veluri
  • 6,671
  • 5
  • 32
  • 56
user1145280
  • 371
  • 1
  • 2
  • 10

2 Answers2

1

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();
}
}
Ankit Kumar
  • 1,433
  • 1
  • 16
  • 24
  • thank you so much for answer, i understood the thing, one ques - i have included both jars now suppose only for 2 functions i have applied fully qualified names (in my case with vngx-jsch) is it sufficient or other place i have to mention with j2ssh ? – user1145280 Feb 24 '14 at 09:04
  • that should work. no need to change in other places. – Ankit Kumar Feb 24 '14 at 09:07
  • and also if you think the answer was useful and answered your question, vote "up" and mark it complete :) – Ankit Kumar Feb 24 '14 at 09:08
  • you should be able to see arrow mark just above the "0", clicking on that means that the answer was useful – Ankit Kumar Feb 24 '14 at 09:12
1

1) can I use both lib ?

Probably yes. But you would need to try it to be sure.

The two things that would be contra-indicative would be:

  • the two libraries defining classes with the same fully qualified class names1, or

  • needing to accept ssh connections in your application using the two libraries using the same port.

2) does it make sense ?

Possibly. But IMO, it makes more sense to either find and fix the root problem2, or recode the application so that it does need the two missing functions.

3) what if I keep j2ssh as it is and only for those 2 function I will load vngx-ssh? is it possible?

It depends what you mean. If you make separate connections using the two libraries then that could work.

how to do it ? any example ?

It depends on the details of your problem. (But you are unlikely to find examples, because what you are doing sounds like an inferior approach ...)


1 - If this is a problem, it may be possible to work around the name clash using classloader magic, but you should only do that as a last resort.

2 - This is one of the advantages of open source. If there is a problem in the application / library you are using, you can find it and fix it ... and then contribute your fix back to the community.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216