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
经过查看错误得知:
于是查看官网文档解决方法如下:
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/lib
directory.cd WL_HOME/server/lib 这里WL_HOME就是我们的D:\Oracle\Middleware\wlserver_12.1
-
Use the following command to create wlfullclient.jar in the
server/lib
directory:java -jar wljarbuilder.jar
-
You can now copy and bundle the
wlfullclient.jar
along withcryptoj.jar
with client applications. Thewlfullclient.jar
andcryptoj.jar
must be kept in the same directory as thewlfullcient.jar
referencescryptoj.jar
in its manifest Class-Path. -
Add the
wlfullclient.jar
to the client application's classpath.
(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
(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:
(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)
以上就是没有切换盘符导致的错误 注意这里