绕过在使用Java模块时的旧Java元信息(META-INF / services)部分。

huangapple go评论89阅读模式
英文:

Circumvent old java meta-inf / services when using Java modules

问题

我正在尝试制作一个使用Batik库显示SVG图像的Java FX应用程序,但在正确导入所有组件方面遇到了问题。

经过大约5个小时的搜索和测试,我终于修改了其中一个依赖库的jar文件,以删除旧的Java服务(或无论您如何称呼它),该服务早于当前的模块系统。因此,目前的解决方法是在batik-script-1.13.jar中手动删除“META-INF/services/org.apache.batik.script.InterpreterFactory”文件。

有没有合适的方法来做到这一点?在我的项目模块信息中,还是通过Maven?而不必手动修改jar文件?

提前感谢! 绕过在使用Java模块时的旧Java元信息(META-INF / services)部分。

如果相关:
Mac OS,Java openjdk-14.0.2,Maven 3.6.3,VSCode 1.49.0

英文:

I am trying to make a Java FX application showing an SVG-image using the Batik-library, but I'm having issues getting all the components properly imported.

After about 5 hours of searching and testing I have finally altered one of the dependencies' jars to remove old Java service (or whatever you call it) that predates the current module system. So the current work-around is to manually remove the "META-INF/services/org.apache.batik.script.InterpreterFactory"-file in "batik-script-1.13.jar".

Is there a proper way to do this? In my projects module-info, or through maven? Without having to manually alter the jar?

Thanks in advance! 绕过在使用Java模块时的旧Java元信息(META-INF / services)部分。

If relevant:
Mac OS, Java openjdk-14.0.2, Maven 3.6.3, VSCode 1.49.0

答案1

得分: 1

TL;DR — 没有办法通过JPMS系统来绕过batik库的java.lang.module.InvalidModuleDescriptorException问题。


详细版本

几个月前我也遇到了同样的问题。我发现,就像你很可能也发现了,这篇旧的Jigsaw Dev邮件列表帖子

>> …
>>
>> > 2) 在初始化引导层时发生错误
>>
>> > java.lang.module.FindException: 无法为
>>
>> > .m2\repository\org\apache\xmlgraphics\batik-script\1.8\batik-script-1.8.jar
>>
>> > 推导模块描述符失败
>>
>> > Caused by: java.lang.module.InvalidModuleDescriptorException: 提供方
>>
>> > 类 org.apache.batik.bridge.RhinoInterpreterFactory 不在模块中
>>
>>
>> 存在一个META-INF/services/org.apache.batik.script.InterpreterFactory配置文件,其中有一个不在此模块中的提供方类。
>>
>> …

回复该帖子的人是Java平台开发团队的成员,拥有数十年的经验

我理解他们“我建议您联系这个库的维护者发布一个可以作为模块运行的版本”的建议是给邮件列表原作者的线索,暗示尝试使用JPMS与batik库是没有希望的。

英文:

TL;DR — There is no way to circumvent the batik library's java.lang.module.InvalidModuleDescriptorException issue using the JPMS system.


The long-winded version

I came across the same issue myself some months ago. I found, like you more than likely also found, this old Jigsaw Dev mailing list post

>> …
>>
>> > 2) Error occurred during initialization of boot layer
>>
>> > java.lang.module.FindException: Unable to derive module descriptor for
>>
>> > .m2\repository\org\apache\xmlgraphics\batik-script\1.8\batik-script-1.8.jar
>>
>> > Caused by: java.lang.module.InvalidModuleDescriptorException: Provider
>>
>> > class org.apache.batik.bridge.RhinoInterpreterFactory not in module
>>
>>
>> There exists META-INF/services/org.apache.batik.script.InterpreterFactory config file with a provider class that is not in this module.
>>
>> …

The person replying to the OP there is a member of the Java Platform Development Team that has decades of experience.

I interpreted their „I suggest you contact the maintainer of this library to publish a version that can be run as a module“ advice to the mailing list OP, as a clue that trying to use the batik library with JPMS is hopeless.

答案2

得分: 1

我在这个问题上纠缠了相当长的一段时间,最终放弃了JPMS,并尝试绕过系统,通过自动化我已经成功实现的JAR修改来解决问题。

通过使用一个名为Truezip的Maven插件,我设置了Maven来自动解压缩、修改,然后重新压缩依赖项。尽管这不是最优雅的解决方案,但它有效,并且我还在另一个存在类似问题的依赖项上使用它。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>truezip-maven-plugin</artifactId>
    <version>1.2</version>
    <executions>
        <execution>
            <id>fix-batik-script</id>
            <goals>
                <goal>remove</goal>
            </goals>
            <phase>process-resources</phase>
            <configuration>
                <fileset>
                    <directory>${settings.localRepository}/org/apache/xmlgraphics/batik-script/1.13/batik-script-1.13.jar/META-INF/services</directory>
                    <includes>
                        <include>org.apache.batik.script.InterpreterFactory</include>
                    </includes>
                </fileset>
            </configuration>
        </execution>
    </executions>
</plugin>
英文:

I was battling this for quite a while, before finally giving up JPMS and trying to circumvent the system by automating the JAR-alterations I had gotten working.

By using a Maven plugin called Truezip I set up Maven to automatically unzip, alter and then rezip the dependency. Even though it's not the most elegant solution, it works, and I'm also using it on another dependency with a similar issue.

&lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
    &lt;artifactId&gt;truezip-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.2&lt;/version&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;id&gt;fix-batik-script&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;remove&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;phase&gt;process-resources&lt;/phase&gt;
            &lt;configuration&gt;
                &lt;fileset&gt;
                    &lt;directory&gt;${settings.localRepository}/org/apache/xmlgraphics/batik-script/1.13/batik-script-1.13.jar/META-INF/services&lt;/directory&gt;
                    &lt;includes&gt;
                        &lt;include&gt;org.apache.batik.script.InterpreterFactory&lt;/include&gt;
                    &lt;/includes&gt;
                &lt;/fileset&gt;
            &lt;/configuration&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;

huangapple
  • 本文由 发表于 2020年9月16日 06:46:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63910813.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定