简体   繁体   English

使用 Tika 和 Java 13 编译应用程序 - 加载模块时出现问题

[英]Compiling application with Tika with Java 13 - problems loading modules

I'm trying to migrate a Java application that uses Tika from OracleJDK 1.8 to OPenJDK 13.我正在尝试将使用 Tika 的 Java 应用程序从 OracleJDK 1.8 迁移到 OPenJDK 13。

My IDE is Eclipse.我的 IDE 是 Eclipse。

I have created the file module-info.java to indicate the required modules for my application.我创建了文件module-info.java来指示我的应用程序所需的模块。

In order to be able to use Tika classes such as AbstractParser , Detector , etc., I have added requires org.apache.tika.core;为了能够使用AbstractParserDetector等 Tika 类,我添加了requires org.apache.tika.core; in module-info.java .module-info.java中。

My code also uses the class org.apache.tika.parser.pdf.PDFParserConfig to extract embedded images:我的代码还使用 class org.apache.tika.parser.pdf.PDFParserConfig提取嵌入图像:

PDFParserConfig pdfConfig = new PDFParserConfig();
pdfConfig.setExtractInlineImages(true);
context.set(PDFParserConfig.class, pdfConfig);'

I get the compilation error:我得到编译错误:

PDFParserConfig cannot be resolved to a type

Eclipse suggests to add requires org.apache.tika.parsers; Eclipse 建议添加requires org.apache.tika.parsers; to module-info.java : Eclipse suggestion screenshot .module-info.javaEclipse 建议截图

When I add this module requirement to module-info.java , the application compiles properly.当我将此模块要求添加到module-info.java时,应用程序可以正确编译。

That is, at this stage we have included in module-info.java :也就是说,在这个阶段我们已经包含在module-info.java

module myapp {
    /** others ... */ 
    requires org.apache.tika.core;
    requires org.apache.tika.parsers;
}

However, when trying to execute the compiled application, we get the error:但是,当尝试执行编译后的应用程序时,我们会收到错误消息:

Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\Admin\.m2\repository\org\apache\tika\tika-parsers\1.24\tika-parsers-1.24.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.apache.tika.parser.onenote.OneNoteParser not in module

Inspecting the project Libraries in Eclipse, I can see that tika-core and tika-parsers (v1.24) are both modular: Eclipse Java Build Path检查 Eclipse 中的项目库,我可以看到 tika-core 和 tika-parsers (v1.24) 都是模块化的: Eclipse ZD52387880E1EA921381 Build Path37

In conclusion: If I don't add org.apache.tika.parsers as a required module, the application won't compile, and if I add it I get the runtime error saying org.apache.tika.parser.onenote.OneNoteParser is not in the module.总之:如果我不添加org.apache.tika.parsers作为必需模块,应用程序将无法编译,如果我添加它,我会收到运行时错误org.apache.tika.parser.onenote.OneNoteParser不在模块中。

I have inspected the JAR files for these packages to see the dependencies they have.我已经检查了这些包的 JAR 文件,以查看它们的依赖关系。 The core packages seems to be right:核心包似乎是正确的:

$ jar --file=tika-core-1.24.jar --describe-module

No module descriptor found. Derived automatic module.

org.apache.tika.core@1.24 automatic
requires java.base mandated
contains org.apache.tika
contains org.apache.tika.concurrent
contains org.apache.tika.config
contains org.apache.tika.detect
contains org.apache.tika.embedder
contains org.apache.tika.exception
contains org.apache.tika.extractor
contains org.apache.tika.fork
contains org.apache.tika.io
contains org.apache.tika.language
contains org.apache.tika.language.detect
contains org.apache.tika.language.translate
contains org.apache.tika.metadata
contains org.apache.tika.mime
contains org.apache.tika.parser
contains org.apache.tika.parser.digest
contains org.apache.tika.parser.external
contains org.apache.tika.sax
contains org.apache.tika.sax.xpath
contains org.apache.tika.utils

...but the 'parsers' jar gives an error: ...但是“解析器” jar 给出了错误:

$ jar --file=tika-parsers-1.24.jar --describe-module

Unable to derive module descriptor for: tika-parsers-1.24.jar
Provider class org.apache.tika.parser.onenote.OneNoteParser not in module

Does this mean the jar package for parsers is not well formed?这是否意味着解析器的 jar package 格式不正确? Is there any workaround for this?有什么解决方法吗?

Thank you.谢谢你。

EDIT: If I try with version 1.24.1, I get the execution error:编辑:如果我尝试使用版本 1.24.1,我会收到执行错误:

Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\Admin\.m2\repository\org\apache\tika\tika-parsers\1.24.1\tika-parsers-1.24.1.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.apache.tika.parser.external.CompositeExternalParser not in module

That is: the failing class is CompositeExternalParser instead of OneNoreParser .也就是说:失败的 class 是CompositeExternalParser而不是OneNoreParser

Inspecting META-INF/services/org.apache.tika.parser.Parser of tika-parsers-1.42.1.jar I can see the entry org.apache.tika.parser.external.CompositeExternalParser` but the package does not contain this class. Inspecting META-INF/services/org.apache.tika.parser.Parser of tika-parsers-1.42.1.jar I can see the entry org.apache.tika.parser.external.CompositeExternalParser` but the package does not contain this class。

So, it seems to be an error in this META-INF file.所以,这似乎是这个 META-INF 文件中的错误。 Id this due to an error when compiling the package and submitting it to Maven Central?这是因为编译 package 并将其提交到 Maven Central 时出现错误吗?

I've found a JIRA issue, TIKA-2929 , where they say "Apache Tika needs to be on the Java Classpath, not the module path".我发现了一个 JIRA 问题TIKA-2929 ,他们说“Apache Tika 需要位于 Java 类路径上,而不是模块路径上”。 I've tried this, but, as explained before, I get a compilation error if I don't add it to the module path and set requires org.apache.tika.parsers;我已经尝试过了,但是,如前所述,如果我不将它添加到模块路径并设置requires org.apache.tika.parsers;我会收到编译错误。 . .

This is a hard puzzle...这是一个很难的谜题...

Ran into the same issues.遇到同样的问题。
Also found the faulty entries in还发现了错误的条目
org.apache.tika.parser.Parser (and also org.apache.tika.parser.Detector ) in META-INF/services/ META-INF/services/中的org.apache.tika.parser.Parser (以及org.apache.tika.parser.Detector

A quick fix is to...一个快速的解决方法是...

  • Unpack those files解压这些文件
  • delete the lines that seem to reference non existing classes删除似乎引用非现有类的行
  • pack them back into the jar将它们装回 jar

My project compiled after that.我的项目在那之后编译。
For sure no longterm solution, but since even older versions i tried ran into that problem, it might help out some people.肯定没有长期解决方案,但由于我尝试过的旧版本也遇到了这个问题,它可能会帮助一些人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM