2013-06-29 138 views
1

我是星號中的絕對newbee。我想通過AMI使用asterisk-java進行事件監聽。我目前使用版本11.2.1星號。當我試圖將代碼編譯爲AMI的asterisk-java無法正常工作

javac -cp asterisk-java-0.3.jar HelloEvents.java 

它成功完成。但是當我嘗試執行該文件時,我給出了以下錯誤。

Exception in thread "main" java.lang.NoClassDefFoundError: HelloEvents 
Caused by: java.lang.ClassNotFoundException: HelloEvents 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266) 
    Could not find the main class: HelloEvents. Program will exit. 

代碼

import java.io.IOException; 

import org.asteriskjava.manager.AuthenticationFailedException; 

import org.asteriskjava.manager.ManagerConnection; 
import org.asteriskjava.manager.ManagerConnectionFactory; 
import org.asteriskjava.manager.ManagerEventListener; 
import org.asteriskjava.manager.TimeoutException; 
import org.asteriskjava.manager.action.StatusAction; 
import org.asteriskjava.manager.event.ManagerEvent; 

public class HelloEvents implements ManagerEventListener 
{ 
    private ManagerConnection managerConnection; 

    public HelloEvents() throws IOException 
    { 
     ManagerConnectionFactory factory = new ManagerConnectionFactory(
       "localhost", "manager", "password"); 

     this.managerConnection = factory.createManagerConnection(); 
    } 

    public void run() throws IOException, AuthenticationFailedException, 
      TimeoutException, InterruptedException 
    { 
     // register for events 
     managerConnection.addEventListener(this); 

     // connect to Asterisk and log in 
     managerConnection.login(); 

     // request channel state 
     managerConnection.sendAction(new StatusAction()); 

     // wait 10 seconds for events to come in 
     Thread.sleep(10000); 

     // and finally log off and disconnectaaaa 
     managerConnection.logoff(); 
    } 

    public void onManagerEvent(ManagerEvent event) 
    { 
     // just print received events 
     System.out.println(event); 
    } 

    public static void main(String[] args) throws Exception 
    { 
     HelloEvents helloEvents; 

     helloEvents = new HelloEvents(); 
     helloEvents.run(); 
    } 
} 
+0

請告訴我們你想究竟如何執行該文件,即命令行 – Jk1

+0

java命令星號java.jar HelloEvents –

+0

試試java命令「;星號java.jar」 HelloEvents – Jk1

回答

1
java -cp ".;asterisk-java.jar" HelloEvents 

工作正常。 而類路徑分隔符取決於操作系統。如果您使用的是linux/mac,請使用:(冒號)代替; (分號)