jco连接SAP时,请务必将文件:sapjcorfc.dll,librfc32放到C:\WINDOWS\system32\下边。
否则报错如下:
xception in thread "main" java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'
JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc [C:\WINDOWS\system32\sapjcorfc.dll: Can't find dependent libraries]. java.library.path [E:\eplat\JDK1.6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;E:\eplat\JDK1.6\jre\bin;D:/Program Files/Java/jdk1.6.0_12/bin/../jre/bin/client;D:/Program Files/Java/jdk1.6.0_12/bin/../jre/bin;D:/Program Files/Java/jdk1.6.0_12/bin/../jre/lib/i386;D:\oracle\product\10.2.0\db_1\bin;D:\OraHome_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;D:\Program Files\SecureCRT\;D:\Program Files\Tcent\QQPCMgr\6.8.2385.401;.;D:\Program Files\Java\jdk1.6.0_12\bin;D:\Program Files\Java\jdk1.6.0_12\jre\bin;;D:\Program Files\Tcent\QQPCMgr\6.8.2385.401]
at com.sap.mw.jco.JCO.
at com.magicoo.sale.sap.SAPConnect.getSAPPoolConnection(SAPConnect.java:13)
at com.magicoo.sale.service.YdmerchanlayerjkService.findFromSap(YdmerchanlayerjkService.java:21)
at com.magicoo.sale.service.YdmerchanlayerjkService$$FastClassByCGLIB$$f845a752.invoke(
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:696)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:631)
at com.magicoo.sale.service.YdmerchanlayerjkService$$EnhancerByCGLIB$$5d826ddb.findFromSap(
at com.magicoo.sale.Test.main(Test.java:20)
先告诉人家,你用的是JCO3.0技术、还是JCO2.0技术,如果是JCO 3.0技术的话,如果你是开发WEB项目的话,那就只需要把【sapjco3.dll】这个文件放在WEB-INF/lib目录下就行了,如果不是WEB项目,那就把【sapjco3.dll】这个文件放在C:\WINDOWS\system32。
如果是JCO2.0技术,我就不太了解了,我从一开始用的就是最新的JCO 3.0技术
追问:
我的是jco2的版本,在xp、win7、win8的同样操作在system32目录放了两个.dll文件都可以正常运行,但是在服务器windows2003上面在system32目录放了,它就是报这样的错。系统都是32位的。好纠结。
追答:
no sapjcorfc in java.library.path 你确定你的2003系统上面的Java环境配置正确?重新配置一下Java环境吧。
To install JCo for Windows unzip the appropriate distribution package into an arbitrary directory {sapjco3-install-path}.
Note: Do not copy the sapjco3.dll neither into the {windows-dir}\system32 nor into the {windows-dir}\SysWOW64 directory. This will break the operability of other JCo versions that are already installed on the same system. Furthermore you would risk that the current installation also would not work anymore, if the sapjco3.dll gets replaced in the respective Windows system directory in the future. Then add {sapjco3-install-path} to the PATH environment variable.
Finally, add {sapjco3-install-path}\sapjco3.jar to your CLASSPATH environment variable.
看起来,你的方法有问题。正确的方法是,解压缩安装文件到一个指定的目录中,然后,增加两个环境变量就 行了。
开发WEB项目的话,那就只需要把【sapjco3.dll】这个文件放在WEB-INF/lib目录下就行了,如果不是WEB项目,那就把【sapjco3.dll】这个文件放在C:\WINDOWS\system32。
再试一试,应该就好了。