按照ashingel 的建议,如果门资源是从JAR 文件运行的,我决定在初始化时将其解压缩到一个临时文件夹中。
有关如何解压缩文件夹的详细信息,请参见我的回答:https ://stackoverflow.com/a/16659655/281469
这是我在初始化时所做的示例用法(注意:Apache Commons IO 依赖项):
//My GATE resources are in the "/gate" folder of the JAR
URI url = getClass().getResource("/gate").toURI();
File gateHome;
if (url.isOpaque()) {
logger.info("Unpacking GATE resources from JAR");
String tempDirectoryPath = FileUtils.getTempDirectoryPath();
String gateResource = "gate";
//Delete any existing temporary directory
FileUtils.deleteDirectory(new File(FilenameUtils.concat(tempDirectoryPath, gateResource)));
String gateHomePath = extractDirectoryFromClasspathJAR(getClass(), gateResource, tempDirectoryPath);
gateHome = new File(gateHomePath);
} else {
gateHome = new File(url);
}
Gate.setGateHome(gateHome);