Mensch und Maschine
Willkommen auf » 2009 » September

Hallo to you!

previously it was all about deploying java applications to Tomcat. Today I’ll explain how to use JAVA-Connector JCo 3.0 on a tomcat webserver.

while JCo 2.0 is pretty good covered, JCo 3.0 is not.

requirements:

jco lib: libsapjco3.so

jco jar: sapjco3.jar

libsapjco3.so must be copied into the JDK folder.

under ubuntu thi is:

/usr/lib/jvm/java-1.5.0-sun/jre/lib/i386

sapjco3.jar must be copied into to classpath of the application that shall be deployed on tomcat. Additionally, sapjco3.jar must be copied in the lib folder of your tomcat6 server installation.

After this you can deploy the app like stated in the previous article.

for questions regarding SAP/JCo you can write me an email or leave a comment

I’ve got one solution for all who want to run jco on tomcat but run into two problems:

1. you can register the DestinationDataProvider only once

2. the method Environment.isDestinationDataProviderRegistered() produces the following exception after several runs

java.lang.ExceptionInInitializerError: Error getting the version of the native layer: java.lang.UnsatisfiedLinkError: com/sap/conn/rfc/driver/CpicDriver.nativeCpicGetVersion

The error is probably caused by a bug in JCo itself. Also possible is that i just have wrong configuration settings. Regardless of that,a solution is regisrtering the DataProvider within an empty try catch block and with that not calling the erroneous jco method..

Code with isDestinationDataProviderSet():

public SAPConnection(SAPServerData serverData){
		this.serverConnectionProperties = new Properties();
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_ASHOST, serverData.getHost());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_SYSNR, serverData.getSystemNr());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_CLIENT, serverData.getClient());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_USER, serverData.getUser());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_PASSWD, serverData.getPassword());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_LANG, serverData.getLanguage());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "5");
		//this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_EXPIRATION_PERIOD, Integer.toString(serverData.getTimeout()));

		//set properties of testsystem provider
		provider.changePropertiesForABAP_AS(serverConnectionProperties);

		//avoid multiple provider loading, which would lead to an exception
		if(!Environment.isDestinationDataProviderRegistered()){
			//register provider
			Environment.registerDestinationDataProvider(provider);
		}

		//try to establish connection
		try{
			this.destination = JCoDestinationManager.getDestination(SAP_SERVER);
			this.repository=this.destination.getRepository();
		}
		catch( JCoException e){
			e.printStackTrace();
			return;
		}
	}

Code without isDestinationDataProviderRegistered():

public SAPConnection(SAPServerData serverData){
		this.serverConnectionProperties = new Properties();
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_ASHOST, serverData.getHost());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_SYSNR, serverData.getSystemNr());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_CLIENT, serverData.getClient());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_USER, serverData.getUser());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_PASSWD, serverData.getPassword());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_LANG, serverData.getLanguage());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "5");
		//this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_EXPIRATION_PERIOD, Integer.toString(serverData.getTimeout()));

		//set properties of testsystem provider
		provider.changePropertiesForABAP_AS(serverConnectionProperties);

		//avoid multiple provider loading, which would lead to an exception.
		try {
			//register provider
			Environment.registerDestinationDataProvider(provider);
		} catch (Exception e1) {}

		//try to establish connection
		try{
			this.destination = JCoDestinationManager.getDestination(SAP_SERVER);
			this.repository=this.destination.getRepository();
		}
		catch( JCoException e){
			e.printStackTrace();
			return;
		}
	}

Hallo an Dich!
Zuletzt ging es an dieser Stelle um das Deployen von Java Anwendungen auf Tomcat. Heute wird das Ganze erweitert um das erfolgreiche Einbinden von SAP’s JAVA-Connector JCo 3.0
JCo 2.0 wird relativ gut im Netz behandelt, doch mit JCo3 sieht es nicht so gut aus.
Was du brauchst:
jco lib: libsapjco3.so
jco jar: sapjco3.jar
libsapjco3.so kommt ins JDK-Verzeichnis.
unter ubuntu ist das:
/usr/lib/jvm/java-1.5.0-sun/jre/lib/i386

Die sapjco3.jar muss in den classpath der Anwendung, die auf tomcat deployed werden soll.
Weiterhin muss die sapjco3.jar im tomcat 6 unter lib kopiert werden. bei mir: (/usr/local/share/tomcat6/lib)
danach kann wie im tomcat deployment text vorgegangen werden, um zu deployen.
Eine Lösung habe ich für alle die, die JCo auf Tomcat6 betreiben wollen, jedoch auf zwei probleme stoßen.

1. Man kann den DestinationDataProvider nur einmal registrieren

2. die Abfrage Environment.isDestinationDataProviderRegistered() produziert nach einigen Durchläufen folgende Exception:

java.lang.ExceptionInInitializerError: Error getting the version of the native layer: java.lang.UnsatisfiedLinkError: com/sap/conn/rfc/driver/CpicDriver.nativeCpicGetVersion

Der Fehler wird vermutlich durch einen Bug in JCo hervorgerufen. Möglich ist auch, dass es an falschen Einstellungen des Dataproviders liegt. Wie auch immer: eine Lösung ist, das setzen dees Dataproviders in einen leeren Try Catch Block zu schreiben und somit die fehlerhafte isDestinationDataProviderSet() methode nicht aufzurufen.

Code mit isDestinationDataProviderSet():

public SAPConnection(SAPServerData serverData){
		this.serverConnectionProperties = new Properties();
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_ASHOST, serverData.getHost());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_SYSNR, serverData.getSystemNr());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_CLIENT, serverData.getClient());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_USER, serverData.getUser());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_PASSWD, serverData.getPassword());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_LANG, serverData.getLanguage());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "5");
		//this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_EXPIRATION_PERIOD, Integer.toString(serverData.getTimeout()));

		//set properties of testsystem provider
		provider.changePropertiesForABAP_AS(serverConnectionProperties);

		//avoid multiple provider loading, which would lead to an exception
		if(!Environment.isDestinationDataProviderRegistered()){
			//register provider
			Environment.registerDestinationDataProvider(provider);
		}

		//try to establish connection
		try{
			this.destination = JCoDestinationManager.getDestination(SAP_SERVER);
			this.repository=this.destination.getRepository();
		}
		catch( JCoException e){
			e.printStackTrace();
			return;
		}
	}

Code ohne isDestinationDataProviderRegistered():

public SAPConnection(SAPServerData serverData){
		this.serverConnectionProperties = new Properties();
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_ASHOST, serverData.getHost());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_SYSNR, serverData.getSystemNr());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_CLIENT, serverData.getClient());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_USER, serverData.getUser());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_PASSWD, serverData.getPassword());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_LANG, serverData.getLanguage());
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
		this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "5");
		//this.serverConnectionProperties.setProperty(DestinationDataProvider.JCO_EXPIRATION_PERIOD, Integer.toString(serverData.getTimeout()));

		//set properties of testsystem provider
		provider.changePropertiesForABAP_AS(serverConnectionProperties);

		//avoid multiple provider loading, which would lead to an exception.
		try {
			//register provider
			Environment.registerDestinationDataProvider(provider);
		} catch (Exception e1) {}

		//try to establish connection
		try{
			this.destination = JCoDestinationManager.getDestination(SAP_SERVER);
			this.repository=this.destination.getRepository();
		}
		catch( JCoException e){
			e.printStackTrace();
			return;
		}
	}

Grog ist DAS Modegetränk, wie der u.g. Artikel bestätigt. Jeder sollte Grog trinken!

Wir sehen uns also in der SCUMM Bar wieder :D

Frohes Plündern und Brandschatzen sei euch gewünscht!

Link: Grog im aller welt