I wanna use the class Base64 from commons-codec 1.5 and when I run the code on Server this works fine. My application runs on Websphere 7.0.
But when I run my JUnit tests the wrong Base64 Class is choosen, when i ask the Class with:
System.out.println(Base64.class.getProtectionDomain().getCodeSource().getLocation());
the output is: file:/C:/EProg/IBM/SDP80/runtimes/base_v7/plugins/com.ibm.ws.prereq.soap.jar
Thats definitly the wrong Version.
And an error occurs because of the wrong Version:
java.lang.NoSuchMethodError:
org/apache/commons/codec/binary/Base64.decodeBase64(Ljava/lang/String;)
The crazy thing is, that happens only it i choose one Test and run it with Run As: JUnit Test in Eclipse, if I run the whole thing with Maven everthing works fine.
I use JUnit 4.8.1 and Eclipse Indigo Service Release 2 with some Plugins for Websphere, GWT and Maven.“
com.ibm.ws.prereq.soap.jaris an OSGi bundle, and in WebSphere (which is built on an OSGi container), the classes inorg.apache.commons.codec.binaryare not visible to applications because that package is not exported by the OSGi bundle (you can examine the list of exported packages by looking at theMETA-INF/MANIFEST.MFfile incom.ibm.ws.prereq.soap.jar). That explains why you don’t encounter any issue when running your application in WebSphere.On the other hand, when you add that JAR to a Java project in Eclipse, it will be treated like a simple JAR, not an OSGi bundle, and all packages will be visible. In your case this creates a conflict with another
commons-codecdependency.I guess that the reason why you don’t encounter that issue in Maven is that
com.ibm.ws.prereq.soap.jaris only a dependency of your Eclipse project, but not of your Maven project.Unfortunately there are not many (simple) ways to solve that issue. One is to remove
com.ibm.ws.prereq.soap.jarfrom your Java project (I doubt that you are actually using Apache SOAP). The other is to change the order, so that your othercommons-codecdependency comes beforecom.ibm.ws.prereq.soap.jar.