2017-11-03 34 views
0

Eclipse에서 sbt 어셈블리를 사용하여 프로젝트를 빌드하고 있습니다. 많은 충돌이 있었기 때문에 매우 크고 복잡한 build.sbt 파일이 있습니다.Apache Tika 1.16 TXTParser sbt 빌드에서 문자 인코딩을 감지하지 못했습니다.

tika 1.16의 PDF, OOXML 및 OpenDocument 파서를 사용하는 모든 것이 pdf, pptx, odt 및 docx 파일에 대해 올바르게 작동합니다. 내 스칼라 코드에서

org.apache.tika.exception.TikaException: Failed to detect the character encoding of a document 
    at org.apache.tika.detect.AutoDetectReader.detect(AutoDetectReader.java:77) 
    at org.apache.tika.detect.AutoDetectReader.<init>(AutoDetectReader.java:108) 
    at org.apache.tika.detect.AutoDetectReader.<init>(AutoDetectReader.java:114) 
    at org.apache.tika.parser.txt.TXTParser.parse(TXTParser.java:79)` 

이 라인에서 : 나는 TXTParser 나는 다음과 같은 오류가 사용 txt 파일 (UTF-8 인코딩)를 구문 분석 할 때 그러나

val content = theParser.parse(stream.open(), chandler, meta, pContext) 

이 스트림은 어디 PortableDataStream, chandler는 새로운 BodyContentHandler이며, meta는 새로운 Metadata이며, pContext는 새로운 ParseContext입니다. 내 스칼라 코드에서

org.apache.jena.shared.SyntaxError: unknown 
    at org.apache.jena.rdf.model.impl.NTripleReader.read(NTripleReader.java:73) 
    at org.apache.jena.rdf.model.impl.NTripleReader.read(NTripleReader.java:58) 
    at org.apache.jena.rdf.model.impl.ModelCom.read(ModelCom.java:305) 

이 라인에서 : 나는 AutoDetectParser를 사용하는 경우

대신 나는 다음과 같은 오류가

스트림 InputStream를입니다
val response = model.read(stream, null, "N-TRIPLES") 

.

나는이 문제가 Tika의 빈 응답 때문이라고 생각합니다. (그래서 같은 문제입니다.)

나는 이것이 아마도 지나치게 복잡한 build.sbt 파일의 종속성 문제 일 것이라고 확신하지만 많은 시간 동안 노력한 후에 필자는 분명 도움이 필요하다.

하나의 긍정적 인 점은 txt 파일을 입력하지 않으면 모든 것이 완벽하게 작동하기 때문에 이것이 내 마지막 문제 일 가능성이 높습니다!

scalaVersion := "2.11.8" 
version  := "1.0.0" 
name := "crawldocs" 
conflictManager := ConflictManager.strict 
mainClass in assembly := Some("com.addlesee.crawling.CrawlHiccup") 
libraryDependencies ++= Seq(
    "org.apache.tika" % "tika-core" % "1.16", 
    "org.apache.tika" % "tika-parsers" % "1.16" excludeAll(
    ExclusionRule(organization = "*", name = "guava") 
), 
    "com.blazegraph" % "bigdata-core" % "2.0.0" excludeAll(
    ExclusionRule(organization = "*", name = "collection-0.7"), 
    ExclusionRule(organization = "*", name = "commons-cli"), 
    ExclusionRule(organization = "*", name = "commons-codec"), 
    ExclusionRule(organization = "*", name = "commons-csv"), 
    ExclusionRule(organization = "*", name = "commons-io"), 
    ExclusionRule(organization = "*", name = "commons-lang3"), 
    ExclusionRule(organization = "*", name = "commons-logging"), 
    ExclusionRule(organization = "*", name = "httpclient"), 
    ExclusionRule(organization = "*", name = "httpclient-cache"), 
    ExclusionRule(organization = "*", name = "httpcore"), 
    ExclusionRule(organization = "*", name = "httpmime"), 
    ExclusionRule(organization = "*", name = "jackson-annotations"), 
    ExclusionRule(organization = "*", name = "jackson-core"), 
    ExclusionRule(organization = "*", name = "jackson-databind"), 
    ExclusionRule(organization = "*", name = "jcl-over-slf4j"), 
    ExclusionRule(organization = "*", name = "jena-cmds"), 
    ExclusionRule(organization = "*", name = "jena-rdfconnection"), 
    ExclusionRule(organization = "*", name = "jena-tdb"), 
    ExclusionRule(organization = "*", name = "jsonld-java"), 
    ExclusionRule(organization = "*", name = "libthrift"), 
    ExclusionRule(organization = "*", name = "log4j"), 
    ExclusionRule(organization = "*", name = "slf4j-api"), 
    ExclusionRule(organization = "*", name = "slf4j-log4j12"), 
    ExclusionRule(organization = "*", name = "xercesImpl"), 
    ExclusionRule(organization = "*", name = "xml-apis") 
), 
    "org.scalaj" %% "scalaj-http" % "2.3.0", 
    "org.apache.jena" % "apache-jena" % "3.4.0" excludeAll(
    ExclusionRule(organization = "*", name = "commons-cli"), 
    ExclusionRule(organization = "*", name = "commons-codec"), 
    ExclusionRule(organization = "*", name = "commons-csv"), 
    ExclusionRule(organization = "*", name = "commons-lang3"), 
    ExclusionRule(organization = "*", name = "httpclient"), 
    ExclusionRule(organization = "*", name = "httpclient-cache"), 
    ExclusionRule(organization = "*", name = "httpcore"), 
    ExclusionRule(organization = "*", name = "jackson-core"), 
    ExclusionRule(organization = "*", name = "jackson-databind"), 
    ExclusionRule(organization = "*", name = "jcl-over-slf4j"), 
    ExclusionRule(organization = "*", name = "jena-rdfconnection"), 
    ExclusionRule(organization = "*", name = "slf4j-api") 
), 
    "org.apache.jena" % "apache-jena-libs" % "3.4.0" excludeAll(
    ExclusionRule(organization = "*", name = "commons-cli"), 
    ExclusionRule(organization = "*", name = "commons-codec"), 
    ExclusionRule(organization = "*", name = "commons-csv"), 
    ExclusionRule(organization = "*", name = "commons-lang3"), 
    ExclusionRule(organization = "*", name = "httpclient"), 
    ExclusionRule(organization = "*", name = "httpclient-cache"), 
    ExclusionRule(organization = "*", name = "httpcore"), 
    ExclusionRule(organization = "*", name = "jackson-core"), 
    ExclusionRule(organization = "*", name = "jackson-databind"), 
    ExclusionRule(organization = "*", name = "jcl-over-slf4j"), 
    ExclusionRule(organization = "*", name = "jena-rdfconnection"), 
    ExclusionRule(organization = "*", name = "slf4j-api") 
), 
    "org.noggit" % "noggit" % "0.6", 
    "com.typesafe.scala-logging" %% "scala-logging" % "3.7.2" excludeAll(
    ExclusionRule(organization = "*", name = "slf4j-api") 
), 
    "org.apache.spark" % "spark-core_2.11" % "2.2.0" excludeAll(
    ExclusionRule(organization = "*", name = "breeze_2.11"), 
    ExclusionRule(organization = "*", name = "hadoop-hdfs"), 
    ExclusionRule(organization = "*", name = "hadoop-annotations"), 
    ExclusionRule(organization = "*", name = "hadoop-common"), 
    ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-app"), 
    ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-common"), 
    ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-core"), 
    ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-jobclient"), 
    ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-shuffle"), 
    ExclusionRule(organization = "*", name = "hadoop-yarn-api"), 
    ExclusionRule(organization = "*", name = "hadoop-yarn-client"), 
    ExclusionRule(organization = "*", name = "hadoop-yarn-common"), 
    ExclusionRule(organization = "*", name = "hadoop-yarn-server-common"), 
    ExclusionRule(organization = "*", name = "hadoop-yarn-server-web-proxy"), 
    ExclusionRule(organization = "*", name = "activation"), 
    ExclusionRule(organization = "*", name = "hive-exec"), 
    ExclusionRule(organization = "*", name = "scala-compiler"), 
    ExclusionRule(organization = "*", name = "spire_2.11"), 
    ExclusionRule(organization = "*", name = "commons-compress"), 
    ExclusionRule(organization = "*", name = "slf4j-api"), 
    ExclusionRule(organization = "*", name = "guava"), 
    ExclusionRule(organization = "*", name = "commons-codec"), 
    ExclusionRule(organization = "*", name = "commons-io"), 
    ExclusionRule(organization = "*", name = "gson"), 
    ExclusionRule(organization = "*", name = "httpclient"), 
    ExclusionRule(organization = "*", name = "zookeeper"), 
    ExclusionRule(organization = "*", name = "jettison"), 
    ExclusionRule(organization = "*", name = "jackson-core"), 
    ExclusionRule(organization = "*", name = "httpcore"), 
    ExclusionRule(organization = "*", name = "bcprov-jdk15on"), 
    ExclusionRule(organization = "*", name = "jul-to-slf4j"), 
    ExclusionRule(organization = "*", name = "jcl-over-slf4j"), 
    ExclusionRule(organization = "*", name = "commons-cli"), 
    ExclusionRule(organization = "*", name = "slf4j-log4j12"), 
    ExclusionRule(organization = "*", name = "curator-framework") 
), 
    "org.scala-lang" % "scala-xml" % "2.11.0-M4", 
    "org.apache.hadoop" % "hadoop-mapreduce-client-core" % "2.7.3" excludeAll(
    ExclusionRule(organization = "*", name = "commons-codec"), 
    ExclusionRule(organization = "*", name = "commons-cli"), 
    ExclusionRule(organization = "*", name = "slf4j-api"), 
    ExclusionRule(organization = "*", name = "commons-io"), 
    ExclusionRule(organization = "*", name = "jettison"), 
    ExclusionRule(organization = "*", name = "avro"), 
    ExclusionRule(organization = "*", name = "commons-compress"), 
    ExclusionRule(organization = "*", name = "slf4j-log4j12"), 
    ExclusionRule(organization = "*", name = "netty") 
), 
    "org.apache.hadoop" % "hadoop-common" % "2.7.3" excludeAll(
    ExclusionRule(organization = "*", name = "commons-codec"), 
    ExclusionRule(organization = "*", name = "commons-cli"), 
    ExclusionRule(organization = "*", name = "slf4j-api"), 
    ExclusionRule(organization = "*", name = "commons-math3"), 
    ExclusionRule(organization = "*", name = "commons-io"), 
    ExclusionRule(organization = "*", name = "jets3t"), 
    ExclusionRule(organization = "*", name = "gson"), 
    ExclusionRule(organization = "*", name = "avro"), 
    ExclusionRule(organization = "*", name = "httpclient"), 
    ExclusionRule(organization = "*", name = "zookeeper"), 
    ExclusionRule(organization = "*", name = "commons-compress"), 
    ExclusionRule(organization = "*", name = "slf4j-log4j12"), 
    ExclusionRule(organization = "*", name = "commons-net"), 
    ExclusionRule(organization = "*", name = "curator-recipes"), 
    ExclusionRule(organization = "*", name = "jsr305") 
) 
) 
assemblyMergeStrategy in assembly := { 
case PathList("META-INF", xs @ _*) => MergeStrategy.discard 
case x => MergeStrategy.first 
} 
+0

당신의 파일을 처리 할 수 ​​있습니다 : 내 build.sbt의 하단에 다음 assemblyMergeStrategy 내 문제를 해결? 그게 Tika 버그인지 또는 프로젝트에서 Tika를 어떻게 사용하는지에 대한 문제입니다. – Gagravarr

+0

Eclipse 프로젝트에서 tika-app 및 tika-parsers 독립 실행 형 jar 파일을 빌드 경로에 넣었습니다. 그 완벽하게 작동 ... 내 build.sbt tika - 응용 프로그램 종속성을 가지고 시도했다 그러나 문제를 기억할 수 없습니다. 나는 다시 시험해 화요일에 여기에 올릴 것이다. (나는 집에서 만든 병을 시험 할 수없는 서비스가 필요하다.) 귀하의 회신에 감사드립니다! – GoBuildAngus

+0

MergeStrategy.concat은 "META-INF/service/* (나는 sbt를 사용하지 않습니다)에 대한 올바른 것 같습니다 . – AndyS

답변

0

...

은 내가 MergeStrategy에서 폐기 선 위에 case x if x.contains("EncodingDetector") => MergeStrategy.deduplicate을 추가했다. 당신은 티카 앱 독립 항아리를 잡아, 그와 함께하려고하면

assemblyMergeStrategy in assembly := { 
case x if x.contains("EncodingDetector") => MergeStrategy.deduplicate 
case PathList("META-INF", xs @ _*) => MergeStrategy.discard 
case x => MergeStrategy.first 
} 
2

위의 코드는 기존의 N-트리플가 레거시 이유 만 존재 구문 분석 호출

마지막으로, 여기에 내가 sbt clean assembly를 사용하여 빌드 내 build.sbt 파일입니다. 이전 판독기는 ASCII 전용입니다. UTF-8은이를 깨뜨릴 것입니다.

apache-jena-libs (type = pom)이 처리되지 않거나 jack을 재 포장하고 Java ServiceLoader가 파일을 저장하는 META-INF/service를 처리하지 않았습니다. Jena는 이것을 초기화에 사용합니다. 같은 이름의 파일을 연결하여 META_INF/service/* 파일을 결합해야합니다.

상세 사항 : https://jena.apache.org/documentation/notes/jena-repack.html 마지막으로 고정

+0

나는 이것을 무시하지 않고, 단지 내장 항아리가 내가 집에서 접근 할 수없는 서비스를 요구하기 때문에 화요일까지는 이것을 시험 할 수 없다. 나는 두 가지 질문을 가지고있다 : 어떻게 txt에 문제가있을 때 다른 파일들이 N-triples 파서와 함께 작동합니까? 의존성으로 maven-shade-plugin을 추가해야합니까? build.sbt의 맨 아래에 META-INF 병합을 처리합니다. 첫 번째 전략으로 수정해야합니까? 도와 주셔서 감사합니다. – GoBuildAngus

+0

M ergeStrategy.concat은 "META-INF/service/*"에 대해 올바른 것으로 보입니다 (비록 sbt를 사용하지 않지만) – AndyS

+0

다음과 같은 오류가 발생했습니다 : '오류 : JNI 오류가 발생했습니다. 다시 시도하십시오 "main"스레드의 예외 java.lang.ClassFormatError : 클래스 파일 끝에있는 여분 바이트'다른 병합 전략을 시도합니다. – GoBuildAngus