EJB_Client结合Weblogic
2015-06-04 14:08
417 查看
EJB客户端代码,服务端代码已经有博文了,已经部署到了weblogic上面
客户端代码建立的JAVA_PROJECT
package example.ejb;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.luzhen.ejb.Ejb_Service;
public class TestWebLogicEJB {
public static void main(String[] args) throws Exception {
Properties properties=new Properties();
//指定InitialContext的实现类名称。这里使用weblogic作为服务器。所以相应的值为weblogic.jndi.WLInitialContextFactory。
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
//连接jndi服务器的url。这里weblogic运行在本机,并且端口号为7001。所以值设置为t3://localhost:7001。
properties.setProperty(Context.PROVIDER_URL,"t3://localhost:7001");
//通过jndi访问指定resource的凭证名称。简单理解为访问这个resource时的用户名。如果这个resource没有设定访问策略,则可以不设。
properties.setProperty(Context.SECURITY_PRINCIPAL,"weblogic");
//通过jndi访问指定resource时与凭证相对应的密码。简单理解为访问这个resource时与用户名相对应的密码。如果这个resource没有设定访问策略,则可以不设。
properties.setProperty(Context.SECURITY_CREDENTIALS,"luzhen123");
Context context = new InitialContext(properties);
Ejb_Service sessionejb = (Ejb_Service)context.lookup("HelloEJB#org.luzhen.ejb.Ejb_Service");
String s = sessionejb.saySomething("EJB");
System.out.println(s);
// SwapEJB swap = (SwapEJB)context.lookup("SwapEJBBean#example.ejb.SwapEJB");
// System.out.println(swap.invoke("test"));
}
}
此时运行java application会报错:
Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/security/acl/UserInfo
at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at example.ejb.TestWebLogicEJB.main(TestWebLogicEJB.java:23)
Caused by: java.lang.ClassNotFoundException: weblogic.security.acl.UserInfo
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more
经过查看错误得知:
于是查看官网文档解决方法如下:
Use the following steps to create a wlfullclient.jar file for a JDK 1.7 client application:
Change directories to the
Use the following command to create wlfullclient.jar in the
You can now copy and bundle the
with
client applications. The
be kept in the same directory as the
its manifest Class-Path.
Add the
the client application's classpath.
打开CMD:
Microsoft Windows [版本 6.2.9200]
(c) 2012 Microsoft Corporation。保留所有权利。
C:\Users\lenovo>d:
D:\>cd D:\Oracle\Middleware\wlserver_12.1\server\lib
D:\Oracle\Middleware\wlserver_12.1\server\lib>java -jar wljarbuilder.jar
成功生成wlfullclient.jar 然后将该jar包 加入到EJB Client工程build path下 即可,运行效果如下:
控制台打印出了:EJB
注意:一定要切换盘符号到d:盘 因为我们的weblogic按照目录在d盘
否则如果不切换盘符的话 运行会报错 效果如下2种情况:
情况1:
Microsoft Windows [版本 6.2.9200]
(c) 2012 Microsoft Corporation。保留所有权利。
C:\Users\lenovo>cd D:\Oracle\Middleware\wlserver_12.1\server\lib
C:\Users\lenovo>java -jar wljarbuilder.jar
Error: Unable to access jarfile wljarbuilder.jar
情况2:
Microsoft Windows [版本 6.2.9200]
(c) 2012 Microsoft Corporation。保留所有权利。
C:\Users\lenovo>java -jar D:\Oracle\Middleware\wlserver_12.1\server\lib\wljarbui
lder.jar
This utility is used to build a single, more easily transported jar out of multi
ple jars
Usage: java com.bea.jarbuilder.JarBuilder [options]
where options include:
-usage get usage information for JarBuilder
-help get usage information for JarBuilder
JarBuilder must be run from the server/lib directory under WL_HOME
Exception in thread "main" java.lang.RuntimeException
at com.bea.jarbuilder.JarBuilder.showUsageError(JarBuilder.java:193)
at com.bea.jarbuilder.JarBuilder.processArgs(JarBuilder.java:134)
at com.bea.jarbuilder.JarBuilder.main(JarBuilder.java:49)
以上就是没有切换盘符导致的错误 注意这里
还有这里
要将服务端的EJB程序的Ejb_Service.java接口 打成jar包加入到客户端EJB的build
path中
客户端代码建立的JAVA_PROJECT
package example.ejb;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.luzhen.ejb.Ejb_Service;
public class TestWebLogicEJB {
public static void main(String[] args) throws Exception {
Properties properties=new Properties();
//指定InitialContext的实现类名称。这里使用weblogic作为服务器。所以相应的值为weblogic.jndi.WLInitialContextFactory。
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
//连接jndi服务器的url。这里weblogic运行在本机,并且端口号为7001。所以值设置为t3://localhost:7001。
properties.setProperty(Context.PROVIDER_URL,"t3://localhost:7001");
//通过jndi访问指定resource的凭证名称。简单理解为访问这个resource时的用户名。如果这个resource没有设定访问策略,则可以不设。
properties.setProperty(Context.SECURITY_PRINCIPAL,"weblogic");
//通过jndi访问指定resource时与凭证相对应的密码。简单理解为访问这个resource时与用户名相对应的密码。如果这个resource没有设定访问策略,则可以不设。
properties.setProperty(Context.SECURITY_CREDENTIALS,"luzhen123");
Context context = new InitialContext(properties);
Ejb_Service sessionejb = (Ejb_Service)context.lookup("HelloEJB#org.luzhen.ejb.Ejb_Service");
String s = sessionejb.saySomething("EJB");
System.out.println(s);
// SwapEJB swap = (SwapEJB)context.lookup("SwapEJBBean#example.ejb.SwapEJB");
// System.out.println(swap.invoke("test"));
}
}
此时运行java application会报错:
Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/security/acl/UserInfo
at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at example.ejb.TestWebLogicEJB.main(TestWebLogicEJB.java:23)
Caused by: java.lang.ClassNotFoundException: weblogic.security.acl.UserInfo
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more
经过查看错误得知:
于是查看官网文档解决方法如下:
Creating a wlfullclient.jar for JDK 1.7 client applications
Use the following steps to create a wlfullclient.jar file for a JDK 1.7 client application:Change directories to the
server/libdirectory.
cd WL_HOME/server/lib 这里WL_HOME就是我们的D:\Oracle\Middleware\wlserver_12.1
Use the following command to create wlfullclient.jar in the
server/libdirectory:
java -jar wljarbuilder.jar
You can now copy and bundle the
wlfullclient.jaralong
with
cryptoj.jarwith
client applications. The
wlfullclient.jarand
cryptoj.jarmust
be kept in the same directory as the
wlfullcient.jarreferences
cryptoj.jarin
its manifest Class-Path.
Add the
wlfullclient.jarto
the client application's classpath.
打开CMD:
Microsoft Windows [版本 6.2.9200]
(c) 2012 Microsoft Corporation。保留所有权利。
C:\Users\lenovo>d:
D:\>cd D:\Oracle\Middleware\wlserver_12.1\server\lib
D:\Oracle\Middleware\wlserver_12.1\server\lib>java -jar wljarbuilder.jar
成功生成wlfullclient.jar 然后将该jar包 加入到EJB Client工程build path下 即可,运行效果如下:
控制台打印出了:EJB
注意:一定要切换盘符号到d:盘 因为我们的weblogic按照目录在d盘
否则如果不切换盘符的话 运行会报错 效果如下2种情况:
情况1:
Microsoft Windows [版本 6.2.9200]
(c) 2012 Microsoft Corporation。保留所有权利。
C:\Users\lenovo>cd D:\Oracle\Middleware\wlserver_12.1\server\lib
C:\Users\lenovo>java -jar wljarbuilder.jar
Error: Unable to access jarfile wljarbuilder.jar
情况2:
Microsoft Windows [版本 6.2.9200]
(c) 2012 Microsoft Corporation。保留所有权利。
C:\Users\lenovo>java -jar D:\Oracle\Middleware\wlserver_12.1\server\lib\wljarbui
lder.jar
This utility is used to build a single, more easily transported jar out of multi
ple jars
Usage: java com.bea.jarbuilder.JarBuilder [options]
where options include:
-usage get usage information for JarBuilder
-help get usage information for JarBuilder
JarBuilder must be run from the server/lib directory under WL_HOME
Exception in thread "main" java.lang.RuntimeException
at com.bea.jarbuilder.JarBuilder.showUsageError(JarBuilder.java:193)
at com.bea.jarbuilder.JarBuilder.processArgs(JarBuilder.java:134)
at com.bea.jarbuilder.JarBuilder.main(JarBuilder.java:49)
以上就是没有切换盘符导致的错误 注意这里
还有这里
要将服务端的EJB程序的Ejb_Service.java接口 打成jar包加入到客户端EJB的build
path中
相关文章推荐
- MySQL 内存和CPU优化相关的参数
- WP runtime post 请求, json 解析
- 数据库中的(if-else)
- Android-UI基础
- LeetCode OJ 之 Merge k Sorted Lists(合并k个有序链表)
- 自己动手写C语言库函数(5)strcpy
- mac appium ios python 之首次运行测试用例
- 远程连接CentOS 6.5 x86_64服务器, 在个人用户名下安装gcc-4.7.3
- 关于ActionBar的向下兼容
- driver: linux2.6 内核模块导出函数实例(EXPORT_SYMBOL) 【转】
- [Erlang]用erlang实现binary_to_term
- 一个自动布署.net网站的bat批处理实例
- iOS 心跳包 HTTP Digest认证 MKNetWork做请求
- LeetCode_17---Letter Combinations of a Phone Number
- 应对ADT(Eclipse)的No more handles解决办法
- 去掉actionbar顶部的阴影
- 应对ADT(Eclipse)的No more handles解决办法
- 客户关系管理
- iOS: 去掉UITableView多选时的blue颜色
- Java eclipse内存设置