`

解决JCO3只能在当前工作路径下获取JCoDestination的问题

    博客分类:
  • SAP
阅读更多

经过反编译SAP的JCO3的java代码,发现:JCO3在FileDestinationsDataProvider类中强制使用当前工作路径为jcoDestination的父路径,要想任意指定路径,一个较快的解决办法就是替换掉com.sap.conn.jco.rt.FileDestinationsDataProvider.java这个类,一下是此类的加强版的java代码:

package com.sap.conn.jco.rt;

import com.sap.conn.jco.ext.*;
import com.sap.conn.jco.util.FastStringBuffer;
import java.io.*;
import java.util.Properties;

public final class FileDestinationsDataProvider implements DestinationDataProvider, ServerDataProvider {
  private static String DESTINATION_FILES_SUFFIX = ".jcoDestination";
  private static String SERVER_CFG_FILES_SUFFIX = ".jcoServer";
  private File destinationDirectory;

  FileDestinationsDataProvider(String directory) throws FileNotFoundException {
    destinationDirectory = null;
    /*
    File destinationDirFile = null;
    FastStringBuffer error = new FastStringBuffer(128);
    destinationDirFile = new File(directory);
    if (checkFile(destinationDirFile, error)) {
      destinationDirectory = destinationDirFile;
    } else {
      throw new FileNotFoundException(error.toString());
    }
    */
  }

  private boolean checkFile(File file, FastStringBuffer error) {
    if (file.exists()) {
      if (file.canRead()) {
        return true;
      }
      if (error != null) {
        error.append("File ");
        error.append(file.getAbsolutePath());
        error.append(" exists, but cannot be read. ");
      }
    } else
    if (error != null) {
      error.append("File ");
      error.append(file.getAbsolutePath());
      error.append(" does not exist. ");
    }
    return false;
  }

  public Properties getDestinationProperties(String destinationName) {
    return loadProperties(destinationName, DESTINATION_FILES_SUFFIX);
  }

  public Properties getServerProperties(String serverName) {
    return loadProperties(serverName, SERVER_CFG_FILES_SUFFIX);
  }

  private Properties loadProperties(String destinationName, String suffix) {
    File destinationFile = new File(destinationDirectory,
                                    (new StringBuilder()).append(destinationName).append(suffix).toString());
    FastStringBuffer buf = new FastStringBuffer(256);
    if (!checkFile(destinationFile, buf)) {
      throw new RuntimeException(buf.toString());
    }
    FileInputStream fis = null;
    Properties properties = new Properties();
    try {
      Properties properties1;
      try {
        properties.load(fis = new FileInputStream(destinationFile));
        properties1 = properties;
      } catch (IOException ex) {
        throw new RuntimeException("Unable to load the destination properties", ex);
      }
      return properties1;
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (Exception e) {}
      }
    }
  }

  public boolean supportsEvents() {
    return false;
  }

  public void setDestinationDataEventListener(DestinationDataEventListener destinationdataeventlistener) {
  }

  public void setServerDataEventListener(ServerDataEventListener serverdataeventlistener) {
  }

}
 



附件里有我打包好的经过修改的JCO3的类库文件!

 

0
1
分享到:
评论
2 楼 23号 2010-12-17  
真他妈的混蛋,真打包成jar文件发布都不行。
1 楼 dasenlin1204 2009-10-08  
请帮忙看一下,我以前用的是sapjco.jar,现在要升级到sapjco3.jar,我手里没有sapjco3的资料,现在要写一个sapjco3接口连接源类,不知道怎么写,请指导一下,我原来的sapjco的写法如下:import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.JCO.Pool;
import com.sap.mw.jco.JCO.Client;

/**
* <p>Title: SAPJCO接口连接源类</p>
* <p>Copyright: Copyright (c) 2006</p>
*/
public class SapJcoDataSource
{
 
  private String strUserName = "";
  private String strPassword = "";
  private String strHost = "";
  private String strClient = "";
  private String strSystemNumber = "";
  private String strLanguage = "EN";
  private int iPoolSize = 5;
  private Pool pool = null;
  private IRepository repository = null;

  /**
   * <p>构造函数</p>
   */
  public SapJcoDataSource()
  {
  }

  public String getUserName()
  {
    return strUserName;
  }
  public void setUserName(String username)
  {
    this.strUserName = username;
  }

  public String getPassword()
  {
    return strPassword;
  }
  public void setPassword(String password)
  {
    this.strPassword = password;
  }

  public String getHost()
  {
    return strHost;
  }
  public void setHost(String host)
  {
    this.strHost = host;
  }

  public String getClient()
  {
    return strClient;
  }
  public void setClient(String client)
  {
    this.strClient = client;
  }

  public String getSystemNumber()
  {
    return strSystemNumber;
  }
  public void setSystemNumber(String sysnr)
  {
    this.strSystemNumber = sysnr;
  }

  public String getLanguage()
  {
    return strLanguage;
  }
  public void setLanguage(String language)
  {
    this.strLanguage = language;
  }

  public int getPoolSize()
  {
    return iPoolSize;
  }
  public void setPoolSize(int poolSize)
  {
    this.iPoolSize = poolSize;
  }

  public IRepository getRepository()
  {
    getConnectionPool();
    return repository;
  }
  public Client getConnection()
  {
    String connectPoolName = getConnectionPool().getName();
    return JCO.getClient(connectPoolName);
  }
  private Pool getConnectionPool()
  {
    if (pool == null)
    {
      String strPoolName = "pool_" + strHost + strSystemNumber + strClient;
      pool = JCO.getClientPoolManager().getPool(strPoolName);
      if (pool == null)
      {
        JCO.addClientPool(strPoolName, iPoolSize, strClient, strUserName,
                          strPassword,
                          strLanguage, strHost, strSystemNumber);
        pool = JCO.getClientPoolManager().getPool(strPoolName);
        pool.setConnectionTimeout(60 * 1000);
        pool.setMaxWaitTime(60 * 1000);
        pool.setMaxConnections(iPoolSize * 2);
      }
      if (repository == null)
      {
        repository = JCO.createRepository("DefaultRepository", strPoolName);
      }
    }
    return pool;
  }

  /**
   * <p>Release a client</p>
   * @param connection the client to release
   */
  public void release(Client connection)
  {
    if (connection == null)
      return;
    try
    {
      JCO.releaseClient(connection);
    }
    catch (Exception e)
    {
      try
      {
        connection.reset();
        JCO.releaseClient(connection);
      }
      catch (Exception e1)
      {
      }
    }
  }

}


相关推荐

    sapjco3.dll结合sapjco3.jar包下载

    是因为没有找到 sapjco3.dll这个库的路径,安装了JDK的环境中,这个库默认的位置不是在system32下,而是在 JDK/JRE/BIN下面。 sapjco3 开发环境设置 1.开发中需要将sapjco3.jar加入到项目的build path中 2.或者将其...

    sapjco3 jar包

    1.sapjco3.dll 需要与 sapjco3.jar 在同一目录 2.设置系统环境变量,将sapjco3所在目录加入系统环境变量 例如: 新建环境变量 变量名: JAVA_SAPJCO 变量值: E:\sapjco3\sapjco3-win32 将新建的 JAVA_SAPJCO 环境...

    sapjco3.dll

    windows环境设置1.sapjco3.dll需要与sapjco3.jar在同一目录2.设置系统环境变量,将sapjco3所在目录加入系统环境变量例如:新建环境变量变量名:JAVA_SAPJCO变量值:E:\ sapjco3 \ sapjco3- win32将新建的JAVA_SAP...

    sapjco3 32位64位.dll+jar

    windows 环境设置 1.sapjco3.dll 需要与 sapjco3.jar 在同一目录 2.设置系统环境变量,将sapjco3所在目录加入系统环境变量 例如: 新建环境变量 变量名: JAVA_SAPJCO 变量值: E:\sapjco3\sapjco3-win32 将新建的 JAVA_...

    sapjco-3.0.9.rar

    3、win环境,将sapjco3.dll文件放入C:\Windows\System32路径下即可。 4、linux环境,则将libsapjco3.so文件放入路径:/usr/local/tools/jco3下(可改) 4.1、把目录/usr/local/tools/jco3添加到LD_LIBRARY_PATH环境...

    SAP JCo3在Linux下安装及连接

    SAP JCo3在LINUX操作系统的安装、直接连接、连接池连接

    sap jco 包含sapjco3.jar libsapjco3.so sapjco3.dll

    最新Windows_64和Linux_64下配置JCo3环境,还有配置说明和测试代码 1)将libsapjco3.so、sapjco3.jar扔到指定目录; 3、把JCo3安装目录添加到LD_LIBRARY_PATH环境变量; 4、把 安装目录sapjco3.jar添加到CLASSPATH环境...

    sapjco30/sapjco3.dll/sapjco3.jar SAP官网2017/7/18更新版本

    sapjco30 SAP官网2017/7/18更新版本,Windows64...因项目开发SAP RFC接口,使用sapjco3.dll/sapjco3.jar,而网上下载多个版本的sapjco3.dll都提示版本等级太低,最后从SAP官网上下载了2017/7/18更新的文件,使用后OK。

    SAPJCO3连接配置(sapjco3-linux_x64-3.0.10)

    1.将sapjco3.jar 文件复制至 $JAVA_HOME/lib/sapjco3.jar 2.将 libsapjco3.so 文件复制至 $JAVA_HOME/jre/lib/amd64/server/libsapjco3.so 3.设置环境变量 CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools....

    sapjco3.jar下载

    sapjco3.jar、sapjco3.dll有些技术不可用,下了三个版本才可以用

    sapjco3-3.1.zip

    下载后运行该命令,-Dfile=路径可以修改成自己的路径 mvn install:install-file -DgroupId=org.hibersap -DartifactId=sapjco3 -Dversion=3.0 -Dpackaging=jar -Dfile=E:/sapjco3/sapjco3-win32/sapjco3.jar

    SAP JCo2 to SAP JCo3

    How to Migrate from SAP JCo2 to SAP JCo3 and use SAP JCo3 in a Multi-Threaded Environment

    sapjco3-windows64-linux64 SAP社区完整版

    自己找了好久的资源,这里提供windows64位和linux64服务器版,sapjco版本为3.0.9,java连接sap系统需要通过sap javaconnect来连接,对于sapjco3.jar系列文件有32位与64位之分。 1)将相对应位数的sapjco3.dll文件拷贝...

    sapjco3下载

    sapjco3下载,解决tomcat启动报错:Native library sapjco3 is too old. Found library C:\Program Files\Java\jdk1.8.0_101\bin\sapjco3.dll has version "720.38", but required is at least version "720.117".

    sapjco3.dll(版本721.619)

    sapjco3.dll文件(版本721.619),放在C:\Windows\System32路径下。

    sapjco3-3.0.jar下载

    sapjco3-3.0.jar下载

    sapjco3.zip

    java 连接SAP相关的环境工具包。 sapjco3.dll sapjco3.jar

    sapjco-sapjco3部署在linux windows所需文件

    sapjco-sapjco3部署在linux windows所需文件,包含jar包,sapjco3.dll,sapjco3.so

Global site tag (gtag.js) - Google Analytics