This is a weird issue. There is some Java code which uses SSH connection to run some comands remotely on a server. When running it in Eclipse, everything works; while if runs it from an pacakged uber jar, it reports the following issue:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Google a lot and find the solution from here:
vpartington commented on Apr 5, 2014
I can only imagine the problem is again caused by the uberjar setup. bcprov-jdk16 has a file called META-INF/BCKEY.SF that might get mangled in a similar manner to the META-INF/services files of TrueZip.
Actually the best advice I can give you is to just not create an uberjar. We’ve tried it numerous times but spent so much time chasing this kind of JAR packaging demons (and again when we added a dependency or upgraded to a new version of a dependency) that we decided to just package JAR dependencies in a lib directory and add a shell script/batch file to build a classpath based on the JARs in that lib directory.
An uber jar means that when packaging the project, it includes all the depended jar files by adding all the classes of them(extracted) into its jar file, this is just my case. Vincent said if using such packaging mechanism, some file(META-INF/BCKEY.SF) of “bcprov-jdk16” will be overrided by other package’s file, which causes this issue.
So the fix is not to use the uber jar packaging mechanism.
After some investigation, the solution is to make a “lib” directory, put all the depended jar files in it, and the project’s jar file in it as well, then use the following command to start it(from here):
- Copy all the depended jar files out first(from here) when running the Maven build;
- Copy the project jar into the same directory as step 1 in the build script;
- In the build script, put everything into a “build” directory including jar files both step above and the startup script, then zip all the content in it as the final package file.