如何在Netbeans Platform项目中使用ServiceLoader添加SPI [英] How do I use ServiceLoader in a Netbeans Platform project to add SPIs

查看:129
本文介绍了如何在Netbeans Platform项目中使用ServiceLoader添加SPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Netbeans 8.0的Netbeans Platform项目中添加MP3功能.我知道可以使用ServiceLoader和用于MP3编解码器的SPI轻松将其添加到javax.sound.sampled库中.

I'm trying to add MP3 capabilities to my Netbeans Platform project in Netbeans 8.0. I understand that this can be easily added to the javax.sound.sampled libraries using ServiceLoader and an SPI for the MP3 codecs.

所以我下载了 MP3 SPI 并将其解压缩,然后在Netbeans中创建了一个Jar包装模块,其中三个jar文件位于zip文件中(一个jar文件位于zip的根目录中,两个jar文件位于lib/下).然后,使需要MP3功能的模块依赖于此包装器模块.但是,当我在这些模块中调用AudioSystem.getAudioFileTypes()时,"MP3"不是其中一种类型(只有"WAVE","AU"和"AIFF")

So I downloaded MP3 SPI and unzipped it, then in Netbeans I created a Jar wrapper module with the three jars that were in the zip file (one jar was in the root of the zip and two were under lib/). Then I made the modules that need the MP3 functionality depend on this wrapper module. But when I call AudioSystem.getAudioFileTypes() in those modules, "MP3" is not one of the types (only "WAVE", "AU" and "AIFF")

我想念什么?

我检查了主jar中META-INF/services下是否列出了正确的文件.

I checked that the correct files are listed under META-INF/services in the main jar.

我是否需要在包装模块中重新创建lib/结构?我为包装器模块使用的代码库是否有所不同?我需要在代码中以某种方式提醒ServiceLoader吗?

do I need to recreate the lib/ structure in my wrapper module? Does it make a difference what code-base I use for the wrapper module? Do I need to alert the ServiceLoader somehow in my code?

这是包装器模块的项目元数据:

Here is the project metadata for the wrapper module:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
    <type>org.netbeans.modules.apisupport.project</type>
    <configuration>
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
            <code-name-base>org.sil.wrapper.mp3spi</code-name-base>
            <suite-component/>
            <module-dependencies/>
            <public-packages>
                <package>javazoom.jl.converter</package>
                <package>javazoom.jl.decoder</package>
                <package>javazoom.jl.player</package>
                <package>javazoom.jl.player.advanced</package>
                <package>javazoom.spi</package>
                <package>javazoom.spi.mpeg.sampled.convert</package>
                <package>javazoom.spi.mpeg.sampled.file</package>
                <package>javazoom.spi.mpeg.sampled.file.tag</package>
                <package>org.tritonus.share</package>
                <package>org.tritonus.share.midi</package>
                <package>org.tritonus.share.sampled</package>
                <package>org.tritonus.share.sampled.convert</package>
                <package>org.tritonus.share.sampled.file</package>
                <package>org.tritonus.share.sampled.mixer</package>
            </public-packages>
            <class-path-extension>
                <runtime-relative-path>ext/mp3spi1.9.5.jar</runtime-relative-path>
                <binary-origin>release/modules/ext/mp3spi1.9.5.jar</binary-origin>
            </class-path-extension>
            <class-path-extension>
                <runtime-relative-path>ext/tritonus_share.jar</runtime-relative-path>
                <binary-origin>release/modules/ext/tritonus_share.jar</binary-origin>
            </class-path-extension>
            <class-path-extension>
                <runtime-relative-path>ext/jl1.0.1.jar</runtime-relative-path>
                <binary-origin>release/modules/ext/jl1.0.1.jar</binary-origin>
            </class-path-extension>
        </data>
    </configuration>
</project>

推荐答案

事实证明SPI正常运行.它可以读取和播放MP3文件.但是,AudioSystem.getAudioFileTypes()列出了可写的文件类型,并且SPI不提供写入MP3文件的功能.它不包含javax.sound.sampled.spi.AudioFileWriter

It turns out that the SPI is working fine. It can read and play an MP3 file. However AudioSystem.getAudioFileTypes() lists file types that are writable, and the SPI doesn't provide the ability to write MP3 files. It doesn't include a provider for javax.sound.sampled.spi.AudioFileWriter

这篇关于如何在Netbeans Platform项目中使用ServiceLoader添加SPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆