Hi all,

I was trying to use JUnit to test an SAP JCO wrapper I had written. I began to notice a problem with re-running the test from the JUnit GUI. I could run the test successfully the first time, but the second run would error with…

java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'

Native Library C:\Dev\externals\sapjco-ntintel-2.0.8\sapjcorfc.dll already loaded in another classloader
at com.sap.mw.jco.JCO.(Unknown Source)
at SAPTest.testSAP(SAPTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

…so I wrote a simplifed JUnit test...

import com.sap.mw.jco.JCO;
import junit.framework.TestCase;

public class SAPTest extends TestCase {
        private String client = "750";
        private String lang = "en";
        private String host = "xyz";
        private String sysnr = "03";

        private String userid = "fred";
        private String password = "super111";

        public void testSAP() {
                // Get a client and connect
                JCO.Client jclient = JCO.createClient(client, userid, password, lang, host, sysnr);

…to check it and it still occurs. I'm starting to think this has something to do with how JUnit use class loaders. Any ideas?

I guess I'm off to start trolling through the JUnit source. :-)



DISCLAIMER:  This electronic message together with any attachments is confidential.  If you are not the intended recipient, do not copy, disclose or use the contents in any way.  Please also advise us by return e-mail that you have received the message and then please destroy.  Carter Holt Harvey is not responsible for any changes made to this message and / or any attachments after sending by Carter Holt Harvey.  We use virus scanning software but exclude all liability for viruses or anything similar in this email or any attachment.