简体   繁体   English

通过Java连接SAP时发生异常

[英]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. 即使sapjco3.jar在我的库路径中,我仍试图通过Java类连接SAP相关文件时遇到此异常。我在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. SAP Java连接器内部使用本机库连接到SAP。 This native library is not the sapjco3.jar but the sapjco3.dll (on Windows systems). 该本机库不是sapjco3.jar,而是sapjco3.dll(在Windows系统上)。 Ie the dll file must be in a folder which is in your Java library path. 也就是说,dll文件必须位于Java库路径中的文件夹中。

The latter is a Java system property, you can access it in your application by calling 后者是Java系统属性,您可以在应用程序中通过调用来访问它

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: 然后,您可以将sapjco3.dll放入库路径中已经存在的一个文件夹中(在Windows上,例如C:\\ WINNT \\ system32之类),或者通过显式设置将库路径设置为特定文件夹库路径:

  • in the application code by setting System.setProperty("java.library.path", "C:\\path\\to\\folder\\with\\dll\\") before accessing the SAP JCo 在访问SAP JCo之前System.setProperty("java.library.path", "C:\\path\\to\\folder\\with\\dll\\")通过设置System.setProperty("java.library.path", "C:\\path\\to\\folder\\with\\dll\\")在应用程序代码中设置
  • or when starting Java with the command line argument -Djava.library.path=C:\\path\\to\\folder\\with\\dll\\ 或使用命令行参数-Djava.library.path=C:\\path\\to\\folder\\with\\dll\\启动Java时

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. 由于将dll放入诸如winnt \\ system32这样的系统特定文件夹中可能不仅对您的应用程序有影响,而且对其他应用程序也有影响,因此建议将包含sapjco3.dll的文件夹添加到应用程序的库路径。 The more flexible way is to specify it via the command line as shown above so you don't have it hard coded. 更为灵活的方法是通过命令行(如上所示)进行指定,因此您无需对其进行硬编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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