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

本文介绍了一种通过修改SAP JCO3中的FileDestinationsDataProvider类来实现自定义jcoDestination文件路径的方法。作者提供了修改后的Java代码示例,允许用户指定任意路径而非仅限于当前工作目录。
部署运行你感兴趣的模型镜像

经过反编译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的类库文件!

 

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值