[英]Error using JLayer library and running in command prompt
我正在使用JavaZOOM JLayer庫,並且構建了一個播放音樂的小程序。 這是代碼:
import javazoom.jl.player.Player;
import java.io.FileInputStream;
public class Test {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream(/*SONG PATH*/);
Player player = new Player(fis); //<-- Here is the problem
player.play();
} catch(Exception e){
}
}
}
當我使用Intellij IDEA(我可以聽到音樂)時,該代碼有效,但是當我嘗試在命令提示符下運行時,它將引發以下錯誤:
Exception in thread "main" java.lang.NoClassDefFoundError: javazoom/jl/player/Player
at Test.main<Test.java:9>
Caused by: java.lang.ClassNotFoundException: javazoom.jl.player.Player
at java.net.URLClassLoader.findClass<Unknown Source>
at java.lang.ClassLoader.loadClass<Unkonwn Source>
at sun.misc.Launcer$AppClassLoader.loadClass<Unknown Source>
at java.lang.ClassLoader.loadClass<Unknown Source>
... 1 more
我是使用外部庫的新手,所以我不知道這是什么問題...
PS:我認為CLASSPATH
變量存在問題,但我不知道使用它。
當使用命令行和javac
編譯代碼時,可以使用外部庫的位置設置-classpath
選項。
因此,您可以執行類似javac -classpath location\\of\\library class_to_compile
。
Oracle關於該主題的文檔非常有用: http : //docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.