我按照here的说明创建了一个远程SessionBean的客户端。我在运行Glassfish 3.1.2 beta的同一台机器上运行客户端。当我使用3.1.2 beta Glassfish中的gf-client.jar时,我得到以下异常,如果我将gf-client.jar从类路径中删除,则会出现相同的异常:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
如果我使用来自Maven存储库的3.1.1 gf-client.jar,我会得到一个巨大的堆栈跟踪,抱怨它无法从Derby中找到我甚至不使用的.jar文件。显然是版本不匹配的问题。
有没有人有一个独立的客户端连接到Glassfish 3.1.2 beta?这在JavaEE 6中有变化吗?
以下是代码:
@Stateless
public class LockTestDeadlockService implements LockTestDeadlockServiceI {
public int getP1Id() throws SQLException {
int parentId = -1;
return parentId;
}
}
@Remote
public interface LockTestDeadlockServiceI {
public int getP1Id() throws SQLException;
public void insertChildUpdateParent(int parentId) throws SQLException;
}
这是我的客户:
public class LoadTestClient {
static Logger logger = Logger.getLogger(LoadTestClient.class);
public static void main(String[] args) {
String jndiName = "java:global/locktest-0.0.1-SNAPSHOT/LockTestDeadlockService";
try {
LockTestDeadlockServiceI lockTestService =
(LockTestDeadlockServiceI) new InitialContext().lookup(jndiName);
logger.info("Got lockTestService Remote Interface");
} catch (NamingException e) {
logger.info("Failed to get lockTestService Remote Interface: " + e);
}
}
}
答案 0 :(得分:0)
简短的回答是,要从客户端连接GF 3.x,您需要使用webstart或package-appclient脚本通过Application Client Container(ACC)安装mini-glassfish。打开gf-client.jar并查看清单文件中的类路径。那里列出了大量的文件。这在GF 2.x中是类似的,但它似乎需要较少的客户端依赖(虽然它与该版本为15MB)。
见这些:
Create an "Application Client" with Maven in Java EE
With which maven dependencies can i create a standalone JMS client for Glassfish?
http://docs.oracle.com/cd/E18930_01/html/821-2418/beakt.html#scrolltoc
http://docs.oracle.com/cd/E18930_01/html/821-2418/beakv.html#beakz