2013-04-05 85 views
0

我在會話Bean中使用了一個方法,該方法被一個IOException異常的try和catch塊所包圍,它看起來像是在製造問題,因爲當我嘗試從一個Java項目客戶端調用某個方法時這裏是我的豆代碼EJB3的例外

package com.et; 
import com.gestionfichier.gestion.*; 
import java.io.IOException; 
import javax.ejb.ApplicationException; 
import javax.ejb.Stateless; 

@Stateless 
public class PremierEJB3Bean implements PremierEJB3 { 

    public String envoicode(String Code) { 
     String s = null; 
     try { 
      s = GestionFichier.CopierCode(Code); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     CompilerFichierC.CompilerFichier(s,s); 
     return "Compilation réussie !"; 
    } 
} 

,這裏是我的客戶bean代碼:

package com.et; 
import javax.naming.Context; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 

public class PremierEJB3Client { 

    public static void main(String[] args) { 
     try { 
      Context context = new InitialContext(); 
      PremierEJB3 beanRemote = (PremierEJB3) 
      context.lookup("PremierEJB3Bean/remote"); 
      System.out.println(beanRemote.envoicode("somthing")); 
     } catch (NamingException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

和這裏是我在控制檯中看到

Exception in thread "main" java.lang.reflect.UndeclaredThrowableException 
at $Proxy0.envoicode(Unknown Source) 
at com.et.PremierEJB3Client.main(PremierEJB3Client.java:15) 
    Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement; 
at java.net.URLClassLoader$1.run(Unknown Source) 
at java.net.URLClassLoader$1.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(Unknown Source) 
at java.lang.ClassLoader.loadClass(Unknown Source) 
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
at java.lang.ClassLoader.loadClass(Unknown Source) 
    And more.... 

所以我很安靜確定在我的bean中的異常導致我這個問題,但我不知道如何解決這個問題

+1

我重新格式化了您的代碼,使其更易於閱讀。下一次您提出問題時,您可以在編輯窗口的預覽中看到它的樣子。 – GameDroids 2013-04-05 19:07:39

+0

整個堆棧跟蹤可能會有所幫助...無法對其進行映像。如果在每行之前用4個空格格式化它,它將出現在可滾動區域中。 – jahroy 2013-04-05 19:21:49

+0

試着圍繞你的所有EJB代碼與catch異常(不IOException),並驗證你的服務器日誌 – 2013-04-05 19:37:48

回答

1

爲了從獨立客戶端執行EJB的JNDI查找,需要添加上下文屬性。

與以下內容類似。

Hashtable<String, String> ht = new Hashtable<String, String>(); 
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); 
Context ct=new InitialContext(ht);