2012-06-13 67 views
2

嘗試讓Elasticsearch運行並編制索引PDF。我不熟悉Java。它在抱怨什麼窗口服務器,我該如何解決它?Elasticsearch:java.lang.InternalError:無法連接到窗口服務器

Jun 13 15:57:23 server.mydomain.com java[22345] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged. 
Exception in thread "elasticsearch[index]-pool-2-thread-1" java.lang.InternalError: Can't connect to window server - not enough permissions. 
    at java.lang.ClassLoader$NativeLibrary.load(Native Method) 
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827) 
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1724) 
    at java.lang.Runtime.loadLibrary0(Runtime.java:823) 
    at java.lang.System.loadLibrary(System.java:1045) 
    at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.awt.Toolkit.loadLibraries(Toolkit.java:1605) 
    at java.awt.Toolkit.<clinit>(Toolkit.java:1627) 
    at java.awt.Color.<clinit>(Color.java:263) 
    at org.apache.pdfbox.pdmodel.PDPage.<clinit>(PDPage.java:80) 
    at org.apache.pdfbox.pdmodel.PDPageNode.getAllKids(PDPageNode.java:212) 
    at org.apache.pdfbox.pdmodel.PDPageNode.getAllKids(PDPageNode.java:218) 
    at org.apache.pdfbox.pdmodel.PDPageNode.getAllKids(PDPageNode.java:184) 
    at org.apache.pdfbox.pdmodel.PDDocumentCatalog.getAllPages(PDDocumentCatalog.java:211) 
    at org.apache.pdfbox.util.PDFTextStripper.writeText(PDFTextStripper.java:322) 
    at org.apache.tika.parser.pdf.PDF2XHTML.process(PDF2XHTML.java:63) 
    at org.apache.tika.parser.pdf.PDFParser.parse(PDFParser.java:140) 
    at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:242) 
    at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:242) 
    at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:120) 
    at org.elasticsearch.plugin.mapper.attachments.tika.TikaExtended.parseToString(TikaExtended.java:48) 
    at org.elasticsearch.index.mapper.attachment.AttachmentMapper.parse(AttachmentMapper.java:309) 
    at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:585) 
    at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:449) 
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:493) 
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:437) 
    at org.elasticsearch.index.shard.service.InternalIndexShard.prepareCreate(InternalIndexShard.java:290) 
    at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:210) 
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:532) 
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:430) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:680) 

回答

7

爲了能夠正確索引PDF,ElasticSearch要求Apache Tika提取文本。 Apache Tika反過來要求Apache PDFBox解析文件進行處理。由於PDF文件的工作方式,PDFBox需要使用Java AWT調用來完成字體,顏色等操作。

您的機器當前未正確設置爲執行圖形操作的Java,因此當PDFBox試圖執行使用AWT處理PDF的東西,它爆炸了。

你有兩種選擇。一種是完成圖形設置,另一種是告訴Java以無頭模式運行。

如果您的谷歌爲您的錯誤消息,那麼你會發現很多有用的答案,關於如何執行適當的OSX設置爲任何選項。 This one看起來是一個很好的例子。在共同與大多數Java的UNIX一些變體,如果你運行Java與

java -Djava.awt.headless=true 

然後,它會使用無頭模式,並不會與真正的圖形系統打權限問題。

2

這是您的應用程序嘗試在無頭環境中使用AWT的結果。

要解決這個問題,請使用告訴AWT使用無頭模式的選項啓動您的應用程序。

-Djava.awt.headless=true