我尝试使用grails app http://grobid.readthedocs.org/en/latest/Grobid-java-library/中的示例来使用de GROBID JAVA API。 JAVA(Netbeans)中的以下代码运行良好:
public static void main(String[] args) {
// TODO code application logic here
String pdfPath = "/home/jose/plantilla_Informatica_2015 (ok).pdf";
String pathGHome = "/home/jose/GROBID_COMPILED/grobid-home";
String pathGProp = "/home/jose/GROBID_COMPILED/grobid-home/config/grobid.properties";
try {
MockContext.setInitialContext(pathGHome, pathGProp);
GrobidProperties.getInstance();
Engine engine = GrobidFactory.getInstance().createEngine();
BiblioItem bi = new BiblioItem();
String doc = engine.processHeader(pdfPath, false, bi);
System.out.println(doc);
} catch (Exception ex) {
Logger.getLogger(GROBID.class.getName()).log(Level.SEVERE, null, ex);
}
finally{
try{
MockContext.destroyInitialContext();
}
catch(Exception ex){
Logger.getLogger(GROBID.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
当我将具有相同集合依赖性的相同代码复制到grails时, 并将grobid-core.jar放在文件夹lib中,它给出了错误:
| Error 2016-03-11 16:50:22,195 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - OperationNotSupportedException occurred when processing request: [GET] /GROB/grobid
Context is read only. Stacktrace follows:
Message: Context is read only
Line | Method
->> 961 | checkWritable in org.apache.naming.NamingContext
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 548 | createSubcontext in ''
| 574 | createSubcontext in ''
| 487 | createSubcontext in org.apache.naming.SelectorContext
| 483 | createSubcontext in javax.naming.InitialContext
| 37 | setInitialContext in org.grobid.core.mock.MockContext
| 76 | setInitialContext in ''
| 17 | index in grob.GrobidController
| 198 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . in java.lang.Thread
Process finished with exit code 137
我的Grobid控制器:
import org.grobid.core.data.BiblioItem
import org.grobid.core.engines.Engine
import org.grobid.core.factory.GrobidFactory
import org.grobid.core.mock.MockContext
import org.grobid.core.utilities.GrobidProperties
class GrobidController {
def index() {
String pdfPath = "/home/jose/plantilla_Informatica_2015 (ok).pdf"
String pathGHome = "/home/jose/GROBID_COMPILED/grobid-home"
String pathGProp = "/home/jose/GROBID_COMPILED/grobid-home/config/grobid.properties"
MockContext.setInitialContext(pathGHome, pathGProp)
GrobidProperties.getInstance()
Engine engine = GrobidFactory.getInstance().createEngine()
BiblioItem bi = new BiblioItem()
String doc = engine.processHeader(pdfPath, false, bi)
println(doc)
MockContext.destroyInitialContext()
}
}
我的BuildConfig依赖项:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
compile "directory-naming:naming-java:0.8"
compile "org.slf4j:slf4j-api:1.7.7"
compile "org.apache.commons:commons-lang3:3.1"
compile "com.cybozu.labs:langdetect:1.1-20120112"
compile "com.google.collections:google-collections:1.0"
compile "net.arnx:jsonic:1.3.5"
compile "fr.limsi.wapiti:wapiti:1.5.0"
compile "commons-io:commons-io:2.0.1"
compile "com.google.guava:guava:16.0.1"
compile "xom:xom:1.2.5"
compile "org.slf4j:slf4j-log4j12:1.7.7"
compile "log4j:log4j:1.2.17"
}
###编辑#####
如果我构建相同应用程序的战争并使用
运行它grails run-war target/GROB-0.1.war
效果很好!!!!
会发生什么? 有帮助吗? 谢谢你。