jboss3.2初步配置使用心得[windows2000+sql server 2000] (轉)
1、和
<1>下載可以到.org">下載,我下的是jboss3.2.1。並且不是那個和整合的版本。
<2>安裝方法就是將解壓到的某個目錄下(例如:我的解到 d:jboss-3.2.1)。
2、
<1>首先必須安裝。jboss不像LOGIC自帶標準開發包。我安裝的是1.4 安裝目錄是C:j2sdk1.4.0 。
<2>設定環境變數
<<1>>JAVA_HOME設定為JDK的安裝目錄(例如:我的為C:j2sdk1.4.0)
<<2>>classpath的設定:看看我的,大家就知道該包含哪些包了
C:j2sdk1.4.0libtools.jar;
D:jboss-3.2.1serverdefaultlibjavax..jar;
D:jboss-3.2.1serverdefaultlibjboss-.jar;
.;
D:jboss-3.2.1clientjbossall-client.jar;
D:jboss-3.2.1client.jar;
D:jboss-3.2.1clientlog4j.jar;
3、執行
進入jboss3.2.1的bin目錄,run.bat就可以了。看到出現
00:59:26,978 INFO [Server] JBoss (MX MicroKernel) [3.2.1 (build: Tag=JBoss_3
_2_1 date=05041533)] Started in 17s:595ms
這樣的提示資訊就說明啟動成功,測試方法如下
你將看到jmx agent view
4、使用
<1>html,測試
jboss的預設web目錄是在jboss-3.2.1serverdefaultdeploy下面。下面就介紹測試jsp,servlet,的方法:
對於測試首先在deploy下建立一個test.war資料夾,然後將html,jsp檔案都可以放到這裡進行測試
例如建立一test.jsp如下:
透過就可得到當前日期時間。
<2>設定 SERVER2000的資料來源然後在jsp中操呼叫操作
<<1>>下載安裝2000的jc(提供)
<<2>>將mssqlserver,msbase,msutil三個jar檔案複製到jboss-3.2.1serverdefaultlib目錄下面
<<3>>將jboss-3.2.1docsexamplesjcamssql-ds.複製一份到jboss-3.2.1serverdefaultdeploy下面
部分修改如下:
com.microsoft.jdbc.sqlserver.SQLServerDriver
上面的配置就是用ds作為資料來源的名稱,用不帶密碼的sa連線sql server的樣板資料庫northwind。你可以作適當的修改。
<<4>>配置完成後,用如下testSql.jsp檔案測試資料庫操作
javax.sql.DataSource ds;
%>
try {
Context ctx = new InitialContext();
ds = (javax.sql.DataSource)ctx.lookup("java:/ds");
} catch (Exception e) {
out.println("erro when connect to java naming ");
}
Connection conn = ds.getConnection();
Statement st = conn.createStatement();
String sqlStr = " * from categories";
ResultSet rs = st.executeQuery(sqlStr);
while ( rs.next() ) {
out.println(rs.getString("categoryName")+"
");
}
rs.close();
st.close();
conn.close();
%>
將輸出categories表的每條記錄的categoryName,值得注意的是在mssql-ds.xml設定的jndi-name是ds,而真正的繫結是
java:/ds。
<3> servlet的配置測試
<<1>>編寫並編譯如下的簡單servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("Hello World");
out.println("
}
}
<<2>>在test.war資料夾下建立一個WEB-INF目錄,裡面再建立一個classes目錄和web.xml檔案目錄結構如下:
[test.war]
[WEB-INF]
[classes]
web.xml
將編譯成功的HelloWorld.class放置到classes目錄下,web.xml內容如下:
BR> ">
透過呼叫 就可以看到hello world的輸出
<4>session bean的測試(Hello)
這是一個簡單的stateless session bean的測試
<<1>>Hello.java
import java..RemoteException;
import javax.ejb.EJB;
public interface Hello extends javax.ejb.EJBObject {
public String hello() throws java.rmi.RemoteException;
}
<<2>>HelloHome.java
import java.rmi.RemoteException;
public interface HelloHome extends javax.ejb.EJBHome {
Hello create() throws java.rmi.RemoteException,javax.ejb.CreateException;
}
<<3>>HelloBean.java
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class HelloBean implements javax.ejb.SessionBean {
private SessionContext ctx;
public void ejbCreate() {
System.out.println("ejbCreate()");
}
public void ejbRemove() {
System.out.println("ejbRemove()");
}
public void ejbActivate() {
System.out.println("ejbActivate()");
}
public void ejbPassivate() {
System.out.println("ejbPassivate()");
}
public void setSessionContext(javax.ejb.SessionContext ctx) {
his.ctx = ctx;
}
public String hello() {
System.out.println("hello()");
return "hello,world";
}
}
<<4>>ejb-jar.xml
BR> '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
''>
<<5>>jboss.xml
<<6>>
編譯3個.java檔案後按照以下路徑存放檔案(假設放到d:sessionEjb下面)
d:sessionEjbHello.class
d:sessionEjbHelloBean.class
d:sessionEjbHelloHome.class
d:sessionEjbMETA-INFejb-jar.xml
d:sessionEjbMETA-INFjboss.xml
然後打包d:sessionEjbjar cvf helloejb.jar *.*,打包後將helloejb.jar放到deploy目錄下面,會在控制檯看到如下輸出
11:35:30,815 INFO [EjbModule] Creating
11:35:30,825 INFO [EjbModule] Deploying Hello
11:35:30,835 INFO [StatelessSessionContainer] Creating
11:35:30,835 INFO [StatelessSessionInstancePool] Creating
11:35:30,835 INFO [StatelessSessionInstancePool] Created
11:35:30,845 INFO [StatelessSessionContainer] Created
11:35:30,845 INFO [EjbModule] Created
11:35:30,845 INFO [EjbModule] Starting
11:35:30,845 INFO [StatelessSessionContainer] Starting
11:35:30,905 INFO [StatelessSessionInstancePool] Starting
11:35:30,905 INFO [StatelessSessionInstancePool] Started
11:35:30,905 INFO [StatelessSessionContainer] Started
11:35:30,905 INFO [EjbModule] Started
11:35:30,905 INFO [EJBDeployer] Deployed: file:/D:/jboss-3.2.1/server/default/d
eploy/helloejb.jar
11:35:30,925 INFO [MainDeployer] Deployed package: file:/D:/jboss-3.2.1/server/
default/deploy/helloejb.jar
表明配置沒有錯誤資訊
測試的客戶端程式碼
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
import java.awt.*;
import java.awt.event.*;
import javax..*;
public class HelloWorldClient extends JFrame implements ActionListener {
public HelloWorldClient() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setTitle("EJBClient");
setSize(300,200);
Container contentPane = getContentPane();
area = new JTextArea(6,20);
subButton = new JButton("Say hello to EJB");
subButton.setActionCommand("sya");
subButton.addActionListener(this);
contentPane.add(area,"Center");
contentPane.add(subButton,"South");
}
public void actionPerformed(ActionEvent e) {
if ( e.getActionCommand().equals("sya") ) {
ejbSays = getEJBInfo();
area.append(ejbSays + "n");
}
}
public String getEJBInfo() {
try {
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("HelloEJB");
HelloHome home = (HelloHome)PortableRemoteObject.narrow(ref,HelloHome.class);
Hello hw= home.create();
ejbSays = hw.hello();
} catch (java.rmi.RemoteException e) {
e.printStackTrace();
} catch ( Throwable t ) {
t.printStackTrace();
} finally {
}
return ejbSays;
}
public static Context getInitialContext() throws Exception {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVR_URL, "localhost:1099");
return new InitialContext(p);
}
public static void main(String[] args) {
JFrame win = new HelloWorldClient();
win.pack();
win.setVisible(true);
}
private String ejbSays="";
private JTextField info;
private JButton subButton;
private JTextArea area;
}
作了一個簡單的gui,主要注意的是getInitalContext()方法jboss的連線引數的設定和getEJBInfo()方法對ejb的呼叫
將編譯好的HelloWorldClient.class,HelloWorldClient$1.class,放置到d:sessionbean目錄下(如果放到別的地方,確定可以
透過路徑找到HelloBean,HelloHome,Hello類
d:sessionbeanjava HelloWorldClient
點按鈕就會返回hello world(做gui是為了複習一下以前的知識)
<5>cmp的測試
此cmp繼續使用上面的資料來源對應的northwind資料庫,要在其中建一個表cd。
<<1>>CD.java
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface CD extends EJBObject {
public Integer getId() throws RemoteException;
public void setId(Integer id) throws RemoteException;
public String getTitle() throws RemoteException;
public void setTitle(String title) throws RemoteException;
public String getArtist() throws RemoteException;
public void setArtist(String artist) throws RemoteException;
public String getType() throws RemoteException;
public void setType(String type) throws RemoteException;
public String getNotes() throws RemoteException;
public void setNotes(String notes) throws RemoteException;
}
<<2>>CDHome.java
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import java.rmi.RemoteException;
import java.util.Collection;
public interface CDHome extends EJBHome {
public CD create(Integer id,String title,String artist,String type,String notes) throws RemoteException,CreateException;
public CD findByPrimaryKey(Integer id) throws RemoteException,FinderException;
public Collection findByType(String type) throws RemoteException,FinderException;
}
<<3>>CDBean.java
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
public abstract class CDBean implements EntityBean {
EntityContext ctx;
public Integer id;
public String title;
public String artist;
public String type;
public String notes;
public Integer ejbCreate(Integer id,String title,String artist,String type,String notes) throws CreateException{
setId(id);
setTitle(title);
setArtist(artist);
setType(type);
setNotes(notes);
return id;
}
public void ejbPostCreate(Integer id,String title,String artist,String type,String notes) {
}
public abstract String getTitle() ;
public abstract void setTitle(String _title) ;
public abstract Integer getId() ;
public abstract void setId(Integer _id);
public abstract String getArtist();
public abstract void setArtist(String _artist) ;
public abstract String getType() ;
public abstract void setType(String _type) ;
public abstract String getNotes() ;
public abstract void setNotes(String _notes);
public void setEntityContext(EntityContext ctx) {
this.ctx = ctx;
}
public void unsetEntityContext() {
ctx = null;
}
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbLoad() {}
public void ejbStore() {}
public void ejbRemove() {}
}
<<4>>ejb-jar.xml
BR> "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
">
FROM cd AS A
WHERE A.type=?1
]]>
<<5>>jboss.xml
BR> "-//JBoss//DTD JBOSS 3.0//EN"
">
<<6>>jbosscmp-jdbc.xml
nbsp;
"-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
">
需要解釋的是
會在部署的時候自動在庫中建立資料表,而在刪除的時候同時刪除對應的表
<<7>>編譯部署
編譯3個.java檔案,按照下面的目錄結構存放(假設放在d:cmpbean下面)
d:cmpbeanCD.class
d:cmpbeanCDHome.class
d:cmpbeanCDBean.class
d:cmpbeanMETA-INFejb-jar.xml
d:cmpbeanMETA-INFjboss.xml
d:cmpbeanMETA-INFjbosscmp-jdbc.xml
打包:d:cmpbeanjar cvf cdejb.jar *.*
將cdejb.jar複製到deploy目錄下
<<8>>客戶端程式碼測試
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
import java.util.*;
public class CDClient {
public static Context getInitialContext() throws Exception {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL, "localhost:1099");
return new InitialContext(p);
}
public static void main(String[] args) {
try {
Context jndiContext = getInitialContext();
Object ref= jndiContext.lookup("ejb/cdbean");
CDHome home = (CDHome)PortableRemoteObject.narrow(ref,CDHome.class);
home.create(new Integer(100),"Bohn jove","rock and roll","rock","a good type");
home.create(new Integer(200),"黑寶","rock","rock","roll star");
home.create(new Integer(300),"mike jackson","sssss","iiop","none");
Collection c = home.findByType("rock");
Iterator i = c.iterator();
while ( i.hasNext() ) {
String ss = ( (CD)javax.rmi.PortableRemoteObject.narrow(i.next(),CD.class)).getNotes();
System.out.println(ss);
}
} catch (java.rmi.RemoteException e) {
e.printStackTrace();
} catch (Throwable t) {
t.printStackTrace();
} finally {
}
}
}
請確保透過類路徑可以找到CD.class,CDHome.Class.
執行java CDclient 將看到如下輸出:
D:cmpbean>java CDClient
a good type
roll star
D:cmpbean>
5、結束語
首先我也是個初學者,自己在csdn上多次提問有關jboss的問題,卻所得到回答甚少。
而且搜尋了很久也找不到相應的文件可以瞭解jboss3.2的使用。
為此希望寫此文件為初學者提供一點幫助,錯誤的地方還請指正。
另外、對於jboss3.2 mssql-xa-ds.xml的設定以及連線池的
使用方法,有誰弄過,請告訴我,不勝感激。 email:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-998899/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- jboss3.2中配置mssqlserver的解決方案?S3SQLServer
- Hibernate配置連線SQL SERVER2000SQLServer
- 請教 jboss3.2 +mysql4。0 配置問題S3MySql
- SQL SERVER 2000壓力測試 (轉)SQLServer
- SQL Server2000的OpenXML特性 (轉)SQLServerXML
- 使用 Solaris 的初步設定(轉)
- 除錯工具TRW2000,VB符號除錯初步(轉)除錯符號
- jdon+hibernate+ sql server 2000 怎麼配置SQLServer
- 配置jsp+jdk1.4+tomcat4.0+servlet+sql server2000(jdbc driver) (轉)JSJDKTomcatServletSQLServerJDBC
- SQL SERVER 2000新增功能介紹1 (轉)SQLServer
- Windows 2000 Server網路元件簡介(轉)WindowsServer元件
- SQL Server 2000詳細安裝過程及配置SQLServer
- 配置sql server 2000以允許遠端訪問SQLServer
- 配置Apache Server + Tomcat (轉)ApacheServerTomcat
- SQL Server 2000中的觸發器使用SQLServer觸發器
- Java的中文程式設計與配置心得 (轉)Java程式設計
- SQL Server 2000怎樣配置傳送電子郵件SQLServer
- 《轉》Sql Server 2005(64位) 連線Sql Server 2000(32位) .SQLServer
- Win Form 的 Splitter 使用心得 (轉)ORM
- 修改Delphi使之適應SQL Server2000 (轉)SQLServer
- 【轉帖】認識SQL Server2000 中的CheckPointSQLServer
- [轉]SQL Server 2000定時執行SQL語句SQLServer
- SQL Server 2000 中清空 LOG 檔案一法 (轉)SQLServer
- 淺談非系統管理員使用者本地登入Windows 2000 server (轉)WindowsServer
- 遠端管理Windwos2000 server 的好辦法 (轉)Server
- 轉一下新浪使用redis的心得Redis
- VB串列埠使用心得兩則 (轉)串列埠
- SQL Server 2000 shrink tempdbSQLServer
- 在WINDOWS SERVER 2003 WEB EDITION上使用SQL SERVER 2000客戶端WindowsServerWebSQL客戶端
- 使用Project 2000管理專案(1)(轉)Project
- 使用Project 2000管理專案(2)(轉)Project
- 使用SQLDMO控制 SQL Server (轉)SQLServer
- [zt] SQL Server 2000複製SQLServer
- SQL SERVER 2000 解除安裝SQLServer
- 監視 SQL Server 2000 阻塞SQLServer
- SQL Server 2000 建立統計SQLServer
- redis的安裝並在java中初步使用(spring配置redis)RedisJavaSpring
- SQL Server 2000 中查詢優化器使用的統計SQLServer優化