WebLogic的研究之三--開發、部署EJB(1) (轉)
LOGIC的研究之三--開發、部署(1)
作者:XYZ
這裡不會討論EJB的概念,只討論如何編寫一個簡單EJB,部署EJB,Weblogic與JBuilder的整合,本文先把介紹僅用文字編輯器編寫一個最簡單的EJB所需要的一切,以讓大家一覽EJB的概貌,然後才介紹如何把Weblogic與JBuilder整合起來,使用JBuilder開發Weblogic的EJB,我相信這樣會得到很好的學習效果,因為這是我學習的路徑,當然我會把我遇到的問題告訴大家,以免大家走彎路。
下面是一個最簡單的EJB所需要的程式碼及說明,手工製作EJB的JAR包比較麻煩,在下,我仿照例子製作了一個 build.cmd 批處理
weblogic-ejb-jar.xml
ejb-jar.xml
/A>Beans 1.1//EN' ''>
package hello;
import java..*;
import javax.ejb.*;
public class HelloWorldBean implements SessionBean {
private SessionContext sessionContext;
public void ejbCreate() {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext context) {
sessionContext = context;
}
public String getHelloWorld(){
return "Hello World!";
}
}
HelloWorld.java
package hello;
import java.rmi.*;
import javax.ejb.*;
public interface HelloWorld extends EJB {
public java.lang.String getHelloWorld() throws RemoteException;
}
HelloWorldHome.java
package hello;
import java.rmi.*;
import javax.ejb.*;
public interface HelloWorldHome extends EJBHome {
public HelloWorld create() throws RemoteException, CreateException;
}
HelloWorldBean.java
package hello;
import java.rmi.*;
import javax.ejb.*;
public class HelloWorldBean implements SessionBean {
private SessionContext sessionContext;
public void ejbCreate() {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext context) {
sessionContext = context;
}
public String getHelloWorld(){
return "Hello World!";
}
}
HelloWorldBeanClient1.java
package hello;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
public class HelloWorldBeanClient1 {
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 50;
private boolean logging = true;
private HelloWorldHome helloWorldHome = null;
private HelloWorld helloWorld = null;
/**Construct the EJB test client*/
public HelloWorldBeanClient1() {
long startTime = 0;
if (logging) {
log("Initializing bean access.");
startTime = System.currentTimeMillis();
}
try {
//get naming context
Context ctx = new InitialContext();
//look up jndi name
Object ref = ctx.lookup("HelloWorld");
//cast to Home interface
helloWorldHome = (HelloWorldHome) PortableRemoteObject.narrow(ref, HelloWorldHome.class);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded initializing bean access.");
log("Execution time: " + (endTime - startTime) + " ms.");
}
HelloWorld hello=helloWorldHome.create();
String str=hello.getHelloWorld();
System.out.println(str);
}
catch(Exception e) {
if (logging) {
log("Failed initializing bean access.");
}
e.printStackTrace();
}
}
//----------------------------------------------------------------------------
// Methods that use Home interface methods to generate a Remote interface reference
//----------------------------------------------------------------------------
public HelloWorld create() {
long startTime = 0;
if (logging) {
log("Calling create()");
startTime = System.currentTimeMillis();
}
try {
helloWorld = helloWorldHome.create();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: create()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: create()");
}
e.printStackTrace();
}
if (logging) {
log("Return value from create(): " + helloWorld + ".");
}
return helloWorld;
}
//----------------------------------------------------------------------------
// Methods that use Remote interface methods to access data through the bean
//----------------------------------------------------------------------------
public String getHelloWorld() {
String returnValue = "";
if (helloWorld == null) {
System.out.println("Error in getHelloWorld(): " + ERROR_NULL_REMOTE);
return returnValue;
}
long startTime = 0;
if (logging) {
log("Calling getHelloWorld()");
startTime = System.currentTimeMillis();
}
try {
returnValue = helloWorld.getHelloWorld();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: getHelloWorld()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: getHelloWorld()");
}
e.printStackTrace();
}
if (logging) {
log("Return value from getHelloWorld(): " + returnValue + ".");
}
return returnValue;
}
//----------------------------------------------------------------------------
// Utility Methods
//----------------------------------------------------------------------------
private void log(String message) {
if (message.length() > MAX_OUTPUT_LINE_LENGTH) {
System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
}
else {
System.out.println("-- " + message);
}
}
/**Main method*/
public static void main(String[] args) {
HelloWorldBeanClient1 client = new HelloWorldBeanClient1();
// Use the client object to call one of the Home interface wrappers
// above, to create a Remote interface reference to the bean.
// If the return value is of the Remote interface type, you can use it
// to access the remote interface methods. You can also just use the
// client object to call the Remote interface wrappers.
}
}
build.cmd
if "" == "%JAVA_HOME%" set JAVA_HOME=java
if "" == "%WL_HOME%" set WL_HOME=weblogic
set MYSERVER=%WL_HOME%myserver
set MYCLASSPATH=%JAVA_HOME%libclasses.zip;%WL_HOME%classes;%WL_HOME%libweblogicaux.jar;%MYSERVER%clientclasses
@REM Create the build directory, and copy the deployment descriptors into it
mkdir build buildMETA-INF
copy *.xml buildMETA-INF
@REM Compile ejb classes into the build directory (jar preparation)
javac -d build -classpath %MYCLASSPATH% HelloWorld.java HelloWorldHome.java HelloWorldBean.java
@REM Make a standard ejb jar file, including XML deployment descriptors
cd build
jar cv0f std_ejb_HelloWorld.jar META-INF hello
cd ..
@REM Run ejbc to create the deployable jar file
java -classpath %MYCLASSPATH% -Dweblogic.home=%WL_HOME% weblogic.ejbc -compiler javac buildstd_ejb_HelloWorld.jar %MYSERVER%ejb_Hello.jar
@REM Compile ejb interfaces & client app into the clientclasses directory
javac -d %MYSERVER%clientclasses -classpath %MYCLASSPATH% HelloWorld.java HelloWorldHome.java HelloWorldBeanClient1.java
作者:XYZ※版權所有
轉載請註明來源
【CGI設計室】
">
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-998622/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ejb
- ① EJB無狀態的bean(建立EJB的基礎教程)Bean
- (1)開發部署離線版本
- weblogic標準化部署大綱Web
- 前後端分離開發部署模式【轉】後端模式
- weblogic指令碼工具WLST(1)Web指令碼
- EJB簡單理解
- weblogic軟體安裝與配置部署大全Web
- 27、EJB與JAVA BEAN的區別?JavaBean
- Liunx(CentOS7)中介軟體Weblogic的安裝與部署CentOSWeb
- 鏈動2+1小程式開發原始碼部署原始碼
- 在CentOS7環境下部署weblogic叢集CentOSWeb
- 8天讓iOS開發者上手Flutter之三iOSFlutter
- 鴻蒙NEXT開發案例:轉盤1W鴻蒙
- Gitlab自動部署之三:Linux免密登入GitlabLinux
- weblogic中介軟體軟體上線標準化部署Web
- gRPC學習之三:初試GO版gRPC開發RPCGo
- Flutter Web 開發部署FlutterWeb
- weblogic多資料來源故障轉移問題Web
- SpringCloud 應用在 Kubernetes 上的最佳實踐 — 部署篇(開發部署)SpringGCCloud
- 玩轉iOS開發:iOS中的NSOperation開發(一)iOS
- [譯] [1] + [2] - [3] === 9!? 型別轉換深入研究型別
- 1、實戰SSH埠轉發
- 1、交換與定址轉發
- 如何控制開放HTTPS服務的weblogic伺服器HTTPWeb伺服器
- Hacking weblogicWeb
- 安卓開發--AIDL研究安卓AI
- 2022最新IntellJ IDEA的zheng開發部署文件IntelIdea
- 2022最新IntellJ IDEA的mall開發部署文件IntelIdea
- 上位機開發之三菱Q系列PLC通訊實踐
- Docker下RabbitMQ四部曲之三:細說java開發DockerMQJava
- 幽默:15年前的EJB和今天的JPA何其相似
- 規範:開發環境部署開發環境
- 每日轉發請求近 1 萬億、峰值 QPS 超 1000 萬,百度轉發引擎 BFE 開源了!
- 玩轉 Cgroup 系列之三:挑戰手動管理 Cgroup
- linux-node開發的部署方式–PM2Linux
- PearProject 在 WSL 下的開發環境部署教程Project開發環境
- Java爬蟲快速開發工具uncs的部署攻略Java爬蟲
- 幽默:無伺服器EJB又回來了伺服器