我正在编写一个需要播放音频的代码,并且在运行IntelliJ形式时可以正常工作,但在运行JAR文件时却不能。我该如何解决类路径问题?
这是播放音频的代码部分:
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
String gongFile = s + "/badbeep.wav";
InputStream in = new FileInputStream(gongFile);
AudioStream audioStream = new AudioStream(in);
AudioPlayer.player.start(audioStream);
这是运行构建的JAR文件时遇到的错误:
130 vapaapoika@vapaapoika 13:04:50 ~ ➜ java -jar /media/C/JForex-3-SDK/classes/artifacts/JForex_3_SDK_jar2/JForex-3-SDK.jar
Exception in thread "main" java.lang.NoClassDefFoundError: sun/audio/AudioStream
at jforex.client.gui.MainGUIMode.main(MainGUIMode.java:65)
Caused by: java.lang.ClassNotFoundException: sun.audio.AudioStream
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more