Maven corrupts WAV file when copying to Java resource dir during build

巧了我就是萌 提交于 2019-12-25 09:25:56

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/44332374/maven-corrupts-wav-file-when-copying-to-java-resource-dir-during-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!