Error connecting to SAP in Linux
I am trying to create a connection to SAP using the following piece of code:

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

JCO.Client mConnection = null;
try {
mConnection = JCO.createClient(this.client, // SAP
client
this.userName.toUpperCase(), // userid
this.password.toUpperCase(), // password
this.language.toUpperCase(), // language
this.hostName, // application server host name
this.system); // system number
mConnection.connect();
}catch (JCO.Exception jex) {
throw new Exception(jex.getMessage());
}catch(Exception ex){
throw new Exception("Exception occured while creating Connection to SAP.");
}

In Windows, I am able to connect to SAP system but when I execute the same in Linux environment I get the following exception:
"Exception in thread main java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC' default_cpc_mode"

I am using JDK 1.4.2 / RedHat Linux 8.0 / sapjco-linuxintel-2.1.2.

Where am I going wrong?
See my tip on deciphering JCO exceptions. In your case, make sure the environment variable LD_LIBRARY_PATH points to the directory where JCO was installed.

This was first published in August 2004