简体   繁体   中英

Exception while connecting SAP through Java

Can you please tell me the solution to fix this below issue ---

This Exception I am getting while trying to connect SAP related files through Java class even though sapjco3.jar is in my library path.I tried this in Windows XP & Windows Server 98.

java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at com.sap.conn.jco.rt.DefaultJCoRuntime.loadLibrary(DefaultJCoRuntime.java:441)
at com.sap.conn.jco.rt.DefaultJCoRuntime.registerNativeMethods(DefaultJCoRuntime.java:307)
at com.sap.conn.jco.rt.JCoRuntime.registerNatives(JCoRuntime.java:987)
at com.sap.conn.rfc.driver.CpicDriver.<clinit>(CpicDriver.java:948)
at com.sap.conn.rfc.engine.DefaultRfcRuntime.getVersion(DefaultRfcRuntime.java:43)
at com.sap.conn.rfc.api.RfcApi.RfcGetVersion(RfcApi.java:259)
at com.sap.conn.jco.rt.MiddlewareJavaRfc.<clinit>(MiddlewareJavaRfc.java:200)
at com.sap.conn.jco.rt.DefaultJCoRuntime.initialize(DefaultJCoRuntime.java:73)
at com.sap.conn.jco.rt.JCoRuntimeFactory.<clinit>(JCoRuntimeFactory.java:23)
at com.sap.conn.jco.rt.RuntimeEnvironment.<init>(RuntimeEnvironment.java:40)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at com.sap.conn.jco.ext.Environment.getInstance(Environment.java:121)
at com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(Environment.java:216)
at de.vogella.sap.rfc.core.connection.Connection.<init>(Connection.java:37)
at struct.actions.GestReservaSap.<clinit>(GestReservaSap.java:63)
at eu.sony.com.moduloreservas.ReservasMainClass.main(ReservasMainClass.java:259)

The SAP Java Connector internally uses a native library to connect to SAP. This native library is not the sapjco3.jar but the sapjco3.dll (on Windows systems). Ie the dll file must be in a folder which is in your Java library path.

The latter is a Java system property, you can access it in your application by calling

System.getProperty("java.library.path")

Then you can put the sapjco3.dll either into one of the folders which are already in your library path (on Windows eg something like C:\\WINNT\\system32) or the other way around set the library path to a specific folder by explicitly setting the library path:

  • in the application code by setting System.setProperty("java.library.path", "C:\\path\\to\\folder\\with\\dll\\") before accessing the SAP JCo
  • or when starting Java with the command line argument -Djava.library.path=C:\\path\\to\\folder\\with\\dll\\

Since putting the dll into a system specific folder like winnt\\system32 may have effects not only to your application but to others as well, it is recommended to add the folder containing the sapjco3.dll to your application's library path. The more flexible way is to specify it via the command line as shown above so you don't have it hard coded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM