문제

I'm trying to distribute a GATE application as a standalone JAR file. I have the GATE plugins as resources on my classpath in the project, but setGateHome() requires a File object, which I can't get from a resource packaged inside a JAR.

I assumed that Java IO would be sufficiently abstracted that the APIs could handle this case, but it turns out that File objects only refer to physical files on disk.

Is there any alternative way to do this with the GATE API? Or some option to force JARs to unpack themselves to a temporary folder before running?

The example in the docs is for a servlet, but in that case it's possible to get a file object from the servlet (I think because WAR files are unzipped by the servlet container).

도움이 되었습니까?

해결책 2

Following ashingel's suggestion I decided to unpack the gate resources to a temporary folder on initialization if it was running from a JAR file.

For details of how to unpack the folder see my answer here: https://stackoverflow.com/a/16659655/281469

Here is an example usage of what I did at initialization (Note: Apache Commons IO dependency):

//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);

다른 팁

From my experience with GATE I can suggest to unpack jar with resources necessary somewhere to local drive.Usually I keep all resources(ANNIE,Tokenizer,JAPEs,Gazetteers) in one folder and use relative paths to these resources. As an additional option you can try to use: http://jenkins.gate.ac.uk/job/GATE-Nightly/javadoc/gate/Gate.html#runInSandbox(boolean) option.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top