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