編譯 SecurityHome 介面時出現:
cannot resolve symbol
symbol : class Security
location: interface securitybeans.SecurityHome
Security create() throws CreateException, RemoteException;
雖然 Security.java(Remote 介面)已編譯產生 Security.class,且與 SecurityHome.java 同目錄,但編譯仍失敗。
// SecurityHome.java
package securitybeans;
import java.rmi.RemoteException;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
public interface SecurityHome extends EJBHome {
Security create() throws CreateException, RemoteException;
}
// Security.java
package securitybeans;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface Security extends EJBObject {
String encrypt(String strSource) throws RemoteException;
String decrypt(String strTarget) throws RemoteException;
}
Java 編譯器在編譯介面時,不會自動搜尋同目錄下的 .class 檔案,只會根據 import 陳述式載入類別。SecurityHome 介面回傳型別為 Security,但未 import securitybeans.Security,導致編譯器找不到符號。
import securitybeans.Security;
securitybeans.Security create() throws CreateException, RemoteException;
javac -d . -classpath . SecurityHome.java
create() 回傳 Remote 介面型別。加上 import securitybeans.Security; 後重新編譯即可解決。