Maven corrupts WAV file when copying to Java resou

2019-09-19 19:23发布

I've got a small Maven Java project which requires the playing of a WAV file, and so I'd prefer to simply put the file into the src/main/resources/* folder for simplicity. However, if the same WAV file which works fine being loaded from disk using AudioSystem.getAudioInputStream(...) is then put in the Maven resources directory, the program throws an instance of RIFFInvalidDataException:

com.sun.media.sound.RIFFInvalidDataException: Chunk size too big
    at com.sun.media.sound.RIFFReader.<init>(RIFFReader.java:82)
at com.sun.media.sound.WaveFloatFileReader.internal_getAudioFileFormat(WaveFloatFileReader.java:65)
    at com.sun.media.sound.WaveFloatFileReader.getAudioFileFormat(WaveFloatFileReader.java:55)
    at com.sun.media.sound.WaveFloatFileReader.getAudioInputStream(WaveFloatFileReader.java:117)
    at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1113)
    at se.kth.speech.coin.tangrams.TangramsClient.playSound(TangramsClient.java:276)
    at se.kth.speech.coin.tangrams.TangramsClient.signalGameStart(TangramsClient.java:335)
    ... 17 more

Moreover, if I use VLC to try to open the WAV file at $PROJECT/target/classes/org/coolproject/audio/, the program actually crashes; The original file is handled without any problems

What on Earth is Maven doing with my audio file(s)? I'm using version 3.3.9/1.7.0.20160603-1931 embedded in Eclipse Neon.3 v4.6.3 (build 20170314-1500) and unfortunately cannot try building the project with a "proper" Maven instance outside of Eclipse because building depends on a nightmare hybrid of an old Eclipse project including both Java source and pre-compiled DLLs and a Java-only Maven project.

2条回答
闹够了就滚
2楼-- · 2019-09-19 19:51

You probably have filtering that has side-effects. As per the resources plugin's docs, you can disable filtering like this:

<project>
...
<build>
    ...
    <resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
    </resource>
    ...
    </resources>
    ...
</build>
...
</project>

To see the docs, look here

查看更多
迷人小祖宗
3楼-- · 2019-09-19 20:10

It could be that the maven resources plugin is filtering your .wav file when it's being copied to the target directory. Check out https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html. You may have to add an exclusion to make sure that no filtering is being done on that particular file.

查看更多
登录 后发表回答