Chapter 1 数据挖掘交友
Configuration of ECLIPSE to use JBOSS and LOMBOZInstall Eclipse. First of all we have to set up Eclipse Integrated Development Environment (IDE) with JBOSS as our application server. 数据挖掘研究院 So go to this page: http://www.eclipse.org/downloads/index.php and download the binary for the Eclipse editor. You can download the appropriate binary for your platform. This tutorial was developed using Linux (Red Hat 8.0) as the operating system. Example : eclipse-SDK-2.1-linux-gtk.zip, eclipse-SDK-2.1-win32.zip 数据挖掘论坛 Note : Eclipse does not include a Java runtime environment (JRE). You will need at least a 1.3 level Java runtime or Java development kit (JDK) installed on your machine in order to run Eclipse. 数据挖掘实验室 Now unzip this file into your home directory. 数据挖掘论坛 - [vishal@localhost eclipse]$ unzip eclipse-SDK-2.1-linux-gtk.zip
- Archive: eclipse-SDK-2.1-linux-gtk.zip
- Archive: eclipse-SDK-2.1-linux-gtk.zip
- inflating: eclipse/plugins/org.eclipse.core.boot_2.1.0/boot.jar
- inflating: eclipse/plugins/org.eclipse.core.boot_2.1.0/splash.bmp
- inflating: eclipse/plugins/org.eclipse.core.boot_2.1.0/boot.xml
- inflating: eclipse/plugins/org.eclipse.core.boot_2.1.0/plugin.properties
- -----------------------------------------------------------------------------
- ----------------------------------------------------------------------------
- -------------------------------------------------------------------------
- inflating: eclipse/install.ini
- inflating: eclipse/startup.jar
- inflating: eclipse/readme/readme_eclipse.html
- 数据挖掘工具
Once you have unzipped this file you will have a directory called "eclipse" in your home directory.Go into that directory and run the script file called "eclipse".
- [vishal@localhost eclipse]$ cd eclipse
- [vishal@localhost eclipse]$ ls
- cpl-v10.html features install.ini plugins startup.jar
- eclipse icon.xpm notice.html readme workspace
- [vishal@localhost eclipse]$ ./eclipse
数据挖掘工具 This will run the Eclipse IDE on your workstation. Let"s get familiar with this environment. 数据挖掘工具 
数据挖掘研究院
Install JBOSS. Now Eclipse is installed and is running on your workstation, let"s install JBOSS. 数据挖掘论坛 You can download JBOSS ready to run. Because JBOSS comes with a simple embedded Database (Hypersonic) and a web server (JBossWEB or Tomcat) you can use it out of the box without any initial configuration. Downloads can be accessed from either the JBOSS Project Page on SourceForge where you will always find up to date downloads (http://sourceforge.net/projects/jboss), or from the JBOSS Home Page where you will find useful information about JBoss, the official, free forums, project information etc., and also the download page http://www.jboss.org/downloads.jsp. For this tutorial we are using JBOSS-3.2.1 with the built-in "Jetty" JBOSSWeb HTTP sever. 数据挖掘实验室 Example : jboss-3.2.1.zip (includes JBossWeb HTTP server and JSP/Servlet engine, EJB, CMP2.0, JCA, IIOP, Clustering, JTS, JMX.) 数据挖掘交友 Note : JBOSS does not include a Java runtime environment (JRE). 数据挖掘论坛 First login as user "root" and then unzip this file in a suitable place where you have enough space. I have unzipped it under an /opt/jboss/ directory. 数据挖掘实验室 It will create a directory named jboss-3.2.1 under /opt/jboss/. 数据挖掘交友 Before you run JBOSS, in order to check your installation of JBOSS, make sure have you have following environment variables set. - JBOSS_HOME: /opt/jboss/jboss-3.2.1
- JAVA_HOME: /usr/java/j2sdk1.4.1_02
- CLASSPATH: /usr/java/j2sdk1.4.1_02/lib/tools.jar
Now go into directory jboss-3.2.1 and you will have all these directories. - [root@localhost jboss-3.2.1]# ls
- bin client docs lib server
Go into the bin directory and you will find a script named run.sh. Run this script from the command line. Hopefully it will start, and you will see this message. - 15:12:59,876 INFO [Server] JBoss (MX MicroKernel) [3.2.1 (build: CVSTag=JBoss_3_2_1 date=200305041533)] Started in 59s:676ms.
Note: This means that JBOSS is installed and running successfully. Now, it"s time to configure it from within the eclipse IDE. 数据挖掘实验室 In order to test JBOSS is running correctly, go to your web browser and access this url "http://localhost:8080/jmx-console/index.jsp". Note: This page is referred as the "JMX Management Console". 数据挖掘实验室 
数据挖掘实验室
If you can access this screen from your browser, JBOSS is running successfully. Note that on this page under the sub-heading of "jboss" there is a link "service=Hypersonic". Go to that link; that will bring up an "MBean View" page. On this page there is an MBean operation called "startDatabaseManager"; go there and press the "Invoke" button. This will bring up the console for the embedded Hypersonic database, from where you can access schemas and do other database management operations. 数据挖掘实验室
数据挖掘工具

数据挖掘研究院
Creating the Database Schema. As mentioned in the case study, the schema for our Store"s Inventory is composed of five relations. We will load this schema in the Hypersonic embedded database. 数据挖掘研究院 In order to that, we will use the following script files. 数据挖掘研究院 a) myStoreSchema.script – to create the database schema. 数据挖掘研究院 b) myStoreSchema.data – to populate the tables with data. 数据挖掘交友 c) myStoreSchemaDrop.script – to drop/delete all tables used in this tutorial. 数据挖掘实验室 Downloads : 数据挖掘交友 myStoreSchema.script 数据挖掘论坛 myStoreSchema.data 数据挖掘工具 myStoreSchemaDrop.script
数据挖掘论坛
First of all copy these 3 files into the $JBOSS_HOME/server/default/data/hypersonic/ directory. In this example it is /opt/jboss/jboss-3.2.1/server/default/data/hypersonic/ 数据挖掘论坛 Now access the HSQL Database Manager using the JMX-Management Console shown above. 数据挖掘实验室 Note: Please drop/delete any tables already present in the database with same name beforehand, or naturally errors will be raised when you will run these scripts. 数据挖掘论坛 On the top level menu of HSQL Database Manager File > Open Script.. > select myStoreSchema.script.

After clicking Open > press Execute SQL Statement and the following screen will appear as shown in the figure below. 数据挖掘实验室
数据挖掘实验室 
Go to View > Refresh Tree. If you can see five new tables created then your schema is ready, and it"s time to populate them with data. 数据挖掘工具 Go to File > Open Script.. > select myStoreSchema.data > Open.. > Execute SQL Statement. 数据挖掘实验室
数据挖掘研究院

Now your data is loaded in the database, in order to verify just execute any query and see the results of that as shown in figure below. 数据挖掘工具 
数据挖掘交友
Make sure you "commit" (Options->commit) to save your schema in the database. 数据挖掘论坛 Note : Shutdown Jboss server as we will run it later from inside eclipse. 数据挖掘论坛 Install Lomboz.In order to run JBOSS from within Eclipse you need a plug-in, and for this tutorial we are using Lomboz which is available from http://sourceforge.net/projects/lomboz or from http://www.objectlearn.com/index.jsp. 数据挖掘实验室 Note : We are using lomboz.21_02.zip for this tutorial. Now unzip this file in a temporary directory; you will have a directory named plugins. Go to the directory plugins/com.objectlearn.jdt.j2ee/servers. This directory contains configuration files for various servers. For this tutorial we supply a configuration file for jboss3.2.1 available under downloads. 数据挖掘实验室 Note : If there are multiple configuration files the plugin will presently default to the first configuration file within the (eclipse/plugins/com.objectlearn.jdt.j2ee/servers/ ) directory in alphabetical order, so rename all the configuration files to a ".bak" extension. This is just to avoid slip-ups whilst we"re learning. 数据挖掘工具 Now, copy the supplied jboss321all.server file into the servers directory. 数据挖掘论坛 - cd plugins/
- [vishal@localhost plugins]$ ls
- com.objectlearn.jdt.j2ee
- [vishal@localhost com.objectlearn.jdt.j2ee]$ cd servers
- [vishal@localhost servers$ ls
- jboss244.server.bak jboss303Tomcat4112.server.bak jboss300all.server.bak jboss321all.server
- tomcat403.server.bak weblogic70.server
- jboss300.server.bak tomcat410.server x.log
Here"s a snippet from the file "jboss321all.server" used for configuration. For this tutorial we will use this file, which you can download under Downloads. 数据挖掘交友
数据挖掘实验室 You can change the various settings in this file according to your environment (e.g. the port number). 数据挖掘工具 Once you have saved this file under the com.objectlearn.jdt.j2ee/servers directory, move the com.objectlearn.jdt.j2ee directory under $HOME/eclipse/plugins/ directory, where $HOME is your home directory. 数据挖掘交友 - [vishal@localhost temp/plugins] mv com.objectlearn.jdt.j2ee /home/vishal/eclipse/plugins/.
Now, we will configure Lomboz using this jboss321all.server file. 数据挖掘实验室 Note : Now you can now delete the temporary directory.
Lomboz Configuration.Now run your Eclipse IDE to configure Lomboz ($HOME/eclipse/eclipse ). 数据挖掘研究院 Go to Window on top level menu > Open Perspective > Java as shown in fig below. 数据挖掘论坛 As we want to customize Java perspective for this tutorial: 数据挖掘交友 
数据挖掘研究院 Go to Window again at top level menu > Customize Perspective > Other. 数据挖掘研究院 
Select Lomboz Actions sub node. 数据挖掘工具 
数据挖掘研究院 Click OK. Now you will have an icon under your top level menu like this. 数据挖掘实验室
数据挖掘实验室

数据挖掘研究院
Click on this icon will have a Lomboz J2EE View window in your workbench. 数据挖掘研究院 
数据挖掘论坛
Now, Lomboz J2EE view is available. Go to Window > Customize Perspective. Select File > New sub node. Select all nodes starting with Lomboz. 数据挖掘实验室 
数据挖掘交友
Select Window > Show view. Select Console, Lomboz J2EE View and others as shown below in figure. 数据挖掘实验室 
数据挖掘论坛
Now click ok. You will have all those options available from File > New > and Lomboz menu will appear, or by right clicking in the Package Explorer a pop up menu will appear.
数据挖掘交友 Configure JBOSS to run from within Eclipse. First of all we have to configure the Java Development settings, because Lomboz requires different directories for source and binaries. 数据挖掘论坛 Go to Window > Preferences > Java > New Project. 数据挖掘研究院 Enter src and bin for the names of these folders, which are the defaults. Please do not modify these names as they are required by some of the Lomboz tasks. 数据挖掘交友 Also, make sure JRE library is set to "JRE_LIB" variable. 数据挖掘交友 
数据挖掘交友
Go to Window on top level menu > Preferences. 数据挖掘交友 
Go to the Lomboz node under the Preferences window. Make sure JDK Tools.jar is set to $JAVA_HOME/lib/tools.jar 
Go to the server definitions sub node under Lomboz node. Select JBOSS 3.2.ALL under Server types and the rest of the options will be filled after loading the server configuration file which we made for this tutorial. 数据挖掘交友 
数据挖掘研究院 Now, under Server Definitions, go to "Classpath" and make sure all the paths are correct. If there is a wrong setting for a path, it will show red crosses with jar icons in Server libraries / Client libraries sub section. 数据挖掘论坛 
数据挖掘研究院 You can add or remove libraries from here. Make sure you "Apply" the changes after altering the various options. 数据挖掘研究院 And now verify your "Classpath Variables". 数据挖掘实验室 Go to Window > Preferences > Java > Classpath Variables 数据挖掘研究院 
If you get all these Classpath variables right according to your environment. 数据挖掘工具
数据挖掘实验室
Test your configuration.To test your configuration, create a J2EE Project as a test. 数据挖掘研究院 Go to File at top level menu > New > Lomboz J2EE Project. 数据挖掘交友 
数据挖掘实验室
Enter "Test" as project name and press Next. 数据挖掘工具 Check your settings here; if you have "Test/src" on build path and "Test/bin" under default output folders then it"s ok. 
Now click on Libraries tab on the Project Creation Wizard. 数据挖掘研究院 Because of a bug in Eclipse 2.1 this library is configured wrongly. So select this library and Remove it. 数据挖掘实验室 
Now, add a new library > Add Library.. > Select JRE System library > Next . 数据挖掘研究院
数据挖掘研究院

数据挖掘论坛 Select Default library and press Finish. 数据挖掘论坛 
数据挖掘研究院
New library is configured. 数据挖掘交友 Note: You have to repeat this step whenever you are creating a new J2EE Project, as there is a bug in eclipse 2.1. 数据挖掘研究院 Now press Next. Go to Web Module > Add.. > Enter Module Name "OnlineBank" > Ok. 数据挖掘工具
数据挖掘研究院

数据挖掘实验室
Go to Ejb Modules tab > Add.. > Enter Module Name "MyBank" > Ok. 数据挖掘论坛

Go to Targeted Server > Add.. > "JBOSS 3.2.1 ALL" . 数据挖掘实验室 Note: "JBOSS 3.2.1 ALL" is not the file name, but the name assigned to server in the "jboss321all.server" file used for configuration showed above. Snippet from file below. - <serverDefinition
- name="JBOSS 3.2.1 ALL"
- ejbModules="true"

数据挖掘实验室
Press Finish. 数据挖掘研究院 Now you will have all these directories and libraries under Test Project in the Package Explorer. 数据挖掘交友 Under Project Test "src" is the directory where all packages for EJB components and Servlets will be developed, that is your java source files. 数据挖掘工具 The "MyBank" directory is your EJB Module and will have 7 files at start shown in fig below. The "OnlineBank" directory is your Web Module and will have 7 files shown in fig below. Your JSP pages will come under this directory for this module. 数据挖掘论坛 Note: If you are interested in Ant (from the Jakarta Project) then note that both modules have an Ant "build.xml" file which is used to build the application.
数据挖掘工具 Now go to top level menu option Window > Show View > Lomboz J2EE View. Lomboz J2EE view will have Test Project , which has two modules "MyBank" and "OnlineBank" using JBOSS 3.2.1 as their default server. 数据挖掘研究院 
Now it"s time to create an EJB, 数据挖掘研究院 Go to File > New > Lomboz EJB creation wizard. 数据挖掘工具 Note: You can access this wizard by right clicking in on project Test in Package Explorer. Go to New > Lomboz EJB creation wizard as explained in the beginning. 数据挖掘实验室 Add package name "au.com.tusc"; you can choose another name if you want. Add "MySession" in Name. Select Stateless Session EJB option.
数据挖掘实验室

数据挖掘实验室 This will create a file "MySessionBean.java" under the "au.com.tusc" package as shown in figure below. 数据挖掘工具 Note: It will generate the bean name, jndi-name and type of bean in the file. Also the name of the file is appended with word "Bean" as you gave the name of the bean as "MySession" only. So be careful with naming conventions, as you only need to specify the bean name in the wizard. Don"t append the word Bean to the name as the wizard will do that for you. 数据挖掘实验室
数据挖掘交友 
数据挖掘论坛
Now we will add a business method via the wizard. 数据挖掘实验室 Go to file "MySessionBean.java" under "Package Explorer" and expand that, right click on "MySessionBean" node as shown in the figure below, select New > Lomboz EJB Method wizard. 数据挖掘工具 In the method signature put "public String learnJ2EE(String messg)", select method type as "Business Method" and Interface Type as "Remote Interface". 数据挖掘研究院 
数据挖掘研究院
This will generate the required signature for your business method in your bean class. 数据挖掘研究院 Now add this line in this method "Me too! "; Code Snippet from Bean file 数据挖掘工具 /**
* @ejb.interface-method
* tview-type="remote"
*
**/
public String learnJ2EE (String messg) {
return "Me too! ";
} 数据挖掘论坛 Save the file. Now we will generate the rest of the files (Home and Remote interfaces along with helper classes, using Xdoclet) required to deploy this bean. 数据挖掘实验室 First add this Bean to the module. Go to Package Explorer > Test > MySessionBean.java > MySessionBean, right click on that; a menu will pop up. Go to Lomboz J2EE on this pop-up menu, and select "Add EJB to module".
数据挖掘研究院 
数据挖掘论坛
Go to Package Explorer > Test > MyBank (which is a directory), right click on that; a menu will pop up. Go to Lomboz J2EE, which is at the bottom of this pop up menu. Select Generate EJB classes. This will generate the required interfaces, helper classes and files related to deployment; that is, deployment descriptors. 数据挖掘交友
数据挖掘实验室 
数据挖掘研究院
It will create a new directory named ejbsrc, which will have a package named au.com.tusc, and under that, remote and home interfaces, along with necessary helper classes, will be generated. 数据挖掘交友 Note: You will not edit any files generated by Xdoclet under "ejbsrc" directory at any time while doing this tutorial. Because every time you use option Generate EJB Classes, it generates the necessary interfaces and helper classes as mentioned above. These files are generated by Xdoclet, after parsing your bean class, which is created by Lomboz bean creation wizard. Xdoclet looks at the various declared tags and methods in the bean class and then generates files accordingly. As a result, you just add business methods and their implementations in the bean class, and the rest is left to Xdoclet. Hence at any time in the development, you won"t need to (and shouldn"t!) edit any generated files. It will become clearer as we progress in this tutorial. 数据挖掘研究院 Also under MyBank > META-INF directory now there are 15 files, which includes ejb-jar.xml and jboss.xml and ejb-generate.xml. Initially there were only 6 files as noted earlier. These extra files are needed for deployment of the bean. 
Now let us deploy this bean without going into any further details of deployment. 数据挖掘研究院 Go to Lomboz J2EE view in your workspace, expand Test > expand MyBank. 数据挖掘实验室 You will have au.com.tusc.MySessionBean added to your MyBank EJB module. Right click on JBOSS 3.2.1 ALL icon as shown in fig below. 数据挖掘交友
数据挖掘实验室

数据挖掘论坛
A menu will pop up; select option Debug Server. It will start the server with Debug mode and after successful start it will show this message in the console under your workspace as shown in the figure below. 
Go to Lombo J2EE View > expand Test > select MyBank and right click on that; a menu will pop up; select option Deploy. 数据挖掘论坛 
数据挖掘工具 Once the bean is deployed, a message will come in your "Console" confirming that, as shown in the figure below. 数据挖掘工具 
数据挖掘实验室
Now we will create a client to access this bean deployed on JBOSS (application sever). Go to Package Explorer > Test > src, right click on that, a menu will pop up > select EJB Test client. 数据挖掘交友 Enter Package name "test" and Client name as "Client". 
Select EjbHome as "MySessionHome" and Ejb Interface as "MySession" > Finish as shown in the figure below. 数据挖掘研究院 
数据挖掘交友 Now the client is generated, it"s time to call business methods on the deployed bean. 数据挖掘研究院 We need some code to invoke the method on the bean.. 数据挖掘论坛 
数据挖掘论坛 Go to Client.java and write these lines under the "testBean()" method. 数据挖掘实验室 String request = "I"m tired of "Hello, world" examples.."; System.out.println("Request from client : " + request); System.out.println("Message from server : " + myBean.learnJ2EE(request) ); 数据挖掘实验室 Code Snippet from Client.java.
数据挖掘实验室 public void testBean() {
try {
au.com.tusc.MySession myBean = getHome().create();
//--------------------------------------
//This is the place you make your calls.
//System.out.println(myBean.callYourMethod());
String request = "I"m tired of "Hello, world" examples..";
System.out.println("Request from client : " + request);
System.out.println("Message from server : " + myBean.learnJ2EE(request) );
} catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
} 数据挖掘工具 Now first select Client node under Package Explorer. Go to top level menu and select this icon as shown below. 数据挖掘论坛  On this icon go to > Run as > Java Application. 数据挖掘论坛

Your Client is going to make a request, the results of which will be displayed in the console under your workspace, as shown below. 数据挖掘交友 数据挖掘论坛

数据挖掘工具 Note: Ignore these exceptions regarding org.apache.log4j.Property as it requires "log4j.properties" on the clients path. We will cover this later on as this doesn"t affect the functioning of the bean. 数据挖掘实验室 数据挖掘实验室
You have successfully created a bean and invoked an operation on it. Now, let"s have a brief overview of J2EE concepts in the next chapter, before we start implementing the case study.
|