[Translation Tutorial] Build J2EE Application Tutorial using JBoss and Eclipse - Chapter 1

xiaoxiao2021-03-06  48

Build a J2EE application tutorial using JBoss and Eclipse

Translation: Raxy

Chapter One

Configure Eclipse and use JBoss and Lomboz

Install Eclipse.

First we have to install Eclipse as an integrated development environment (IDE) and JBoss as our application server.

Go to this page: http://www.eclipse.org/downloads/index.php Download the Eclipse Editor's binary. You can download the appropriate binaries based on your platform. This tutorial is under Linux (Red Hat 8.0) Developed.

Example: eclipse-sdk-2.1-linux-gtk.zip, Eclipse-sdk-2.1-win32.zip

Note: Eclipse does not include Java's running environment (JRE). You need to download a Java runtime java development package (JDK) installed on your machine to make Eclipse can run on your machine.

Unzip the 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

-------------------------------------------------- ---------------------------

-------------------------------------------------- ----------------------------

-------------------------------------------------- -----------------------

INFLITING: Eclipse / Install.ini

INFLITIPSE / Startup.jar

Inflating: eclipse / readme / readme_eclipse.html

?

Once you decompress this file, you will find a directory called 'Eclipse' in the home directory.

Go to the directory and run '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

It will launch Eclipse IDE on your workstation. Let us be more familiar with this environment.

Install JBoss.

Since Eclipse has installed and can run on your workstation, then we start to install JBoss.

You can download JBoss you can run directly. Because JBoss has a simple database (Hypersonic) and web server (JBossWeb or Tomcat) you can use it directly without any settings. You can in SourceForge (http: // sourceforge The page download of the .NET / Projects / JBoss project, where you can find the latest version, or to the JBoss's homepage, you can find a lot of useful information about JBoss, such as official information, free forum, and project Information, etc., can also be downloaded from http://www.jboss.org/downloads.jsp. In this tutorial, we use Jetty 'JBoss-3.2.1 as a JBoss HTTP network server. Example : jboss-

3.2.1

.zip (including JBossWeb HTTP Server and JSP / Servlet Engine, EJB, CMP2.0, JCA, IIOP, Clustering, JTS, JMX.)

Note: JBoss does not include Java Run Environment (JRE).

First use the user 'root' to log in and then extract this file to the appropriate location, where there must be enough space. I extract it to the / opt / jboss / directory.

It will create a directory called JBoss-3.2.1 in / OPT / JBOSS /.

Before running JBOSS, in order to check if the JBoss installation is correct, verify that you set the following variables.

JBoss_Home: / OPT / JBOSS / JBOSS-

3.2.1

Java_home: / usr / java / j2sdk

1.4.1

_02

Classpath: / usr / java / j2sdk

1.4.1

_02 / lib / Tools.jar

?

Enter the JBOSS-3.2.1 directory and you will find all of these directories.

[root @ localhost jboss-

3.2.1

] # ls

BIN Client Docs Lib Server

Enter the bin directory and you will find the run.sh script file.

Run the file in the command line. It will start, you will see this information below.

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 is to say that JBoss has been installed and run successfully. It is time to configure it in the Eclipse IDE.

In order to verify that the JBoss runs correct, enter the following address 'http:// localhost: 8080 / jmx-console / index.jsp' in your browser.

Note: This page points to 'JMX Management Console'. If you can access it in your browser, your JBoss has been successful.

Under the 'JBoss' subtitle of this page, there is a link to 'service = hypersonic'. Click this link; there will be 'MBean View' page. There is a MBean operation called 'StartDatabaseManager'; found there and then press it The 'INVOKE' button will appear in the embedded database Hypersonic, where you can access database modes or perform other database management operations.

Create a database mode.

In the study case, our store warehouse database model consists of five relationships. We will load it in the embedded database Hypersonic.

For this purpose, we will use the following script files.

a) MyStoreSchema.script - Used to create database mode .b) MyStoreSchema.Data - Used to add data to the table.

c) MyStoreSchemAdrop.script - The table used to delete the tutorial.

download:

MyStoreSchema.Script

MyStoreschema.Data

MyStoreschemAdrop.script

?

First copy these three files to $ jboss_home / server / default / data / hypersonic / directory. This example is / opt / jboss / jboss-

3.2.1

/ Server / Default / Data / Hypersonic /

The HSQL Database Manager is now accessed using the JMX-Management Console shown in the above figure.

? Note: Please delete the table already existing and we used in the database. Otherwise, there will be an error when you run these scripts.

• Select File> Open script ..> in the menu at the top of the HSQL Database Manager. Script.

Press 'Execute SQL Statement' after you click Open, which will become like shown below.

Select View> Refresh Tree in the menu. If you see that there are 5 new tables created, you explain that your data mode is done, it is when it is added to the table.

?

Select File> Open script ..> in the menu. Select MyStoreSchema.Data> Open ..> Execute Sql Statement.

?

Now your data is already loaded into your database, you can perform any query (here you are using the Select * from storeAccess) to verify it and you can see the same results like the following table.

Make sure you use 'commit' (options-> commit) Save your database mode in your database.

Note: Close the JBoss server because we will run it in Eclipse.

Install Lomboz.

To run JBoss in Eclipse you need a plugin, we use Lomboz in this education to download at http://sourceforge.net/projects/lomboz or http://www.objectLearn.com/index.jsp.

Note: We are using Lomboz.21_02.zip here.

Unzip the file to the temporary directory; you will find a directory called plugins. Enter the directory plugins / com.objectLearn.jdt.j2ee / servers. This directory includes configuration files for various servers. In this tutorial, we offer a JBoss3 .2. The configuration file is available for download.

Note: If there are multiple profiles exist, the plugin will default to use the first profile of the Eclipse / Plugins / Com.objectLearn.jdt.j2ee / Servers / directory, so the suffix name of all configuration files Change to '.bak'. This is to avoid errors in our teaching.

Copy the JBoss321all.server file we provide to 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?

This is a fragment used to configure in 'jboss321all.server' file. In this tutorial we will use this file, you can download in Downloads.

Downloads: jboss321all.server

You can modify the settings (for example, port number) in this file (for example,. Port number).

After you save this file to the com.objectlearn.jdt.j2ee / servers directory, move the com.objectLearn.jdt.j2ee directory to $ HOME / Eclipse / Plugins / Directory ($ HOME is your home directory.)

[Vishal @ localhost temp / plugins] mv com.ObjectLearn.jdt.j2ee / home / Vishal / Eclipse / Plugins /.

Now we will use the JBoss321all.server file to configure Lomboz.

Note: You can now delete the temporary directory.

?

Configure Lomboz.

Now come to run Eclipse to configure Lomboz ($ HOME / Eclipse / Eclipse).

Select Window> Open Perspective> Java in the top menu is just as shown below.

In this tutorial we want to order Java perspective:

Select Window> Customize Perspective> Other in the top menu again.

Check the Lomboz Action Son Node.

Click OK. Now there is an icon like this below the top menu.

Click on this icon to appear in your Workbench, a Lomboz J2EE VIEW window appears.

Now, Lomboz J2EE View is available.

Select Window> Customize Perspective.

Expand the sub-node of File> New. Check all nodes starting with Lomboz.

Then expand the Window> Show View item. Select Console, Lomboz J2EE View, and several other items as shown below.

Click OK now. You will find that all of these options appear in File> New> of the top menu and will also appear in the Lomboz menu, or right-click in the package explorer, one menu will pop up.

Configure jboss and run in Eclipse.

First we have to configure the relevant settings for Java development because Lomboz needs to save source code and bytecode using different directories.

Select Window> Preferences> Expand Java Node> Select the New Project item.

Enter SRC and bin in the corresponding box as the name of the directory, they are default. Please do not modify these default names because they will be used in some Lomboz tasks.

Similarly, determine that JRE Library is set to 'JRE_LIB' Variable.

Select Window> Preferences in the top menu.

Select the Lomboz node in the Preferences window. Confirm that JDK Tools.jar is set to $ java_home / lib / Tools.jar

Select the Server Definitions sub-point in the Lomboz node. Select JBoss 3.2.all in Server Types as Server Types. After selecting it, the rest of the options will be automatically loaded for tutorial.

Select the 'ClassPath' label under Server Definitions and confirm that all paths are correct. If the set path is incorrect, the Jar icon in the child of Server Libraries / Client Libraries will have a red fork.

You can add or delete class libraries here. After you change these options, click 'Apply' to confirm the application.

Now to verify your 'ClassPath Variables'. Select Window> Preferences> Java> ClassPath Variables

You should get all these ClassPath variables that are justice with your development environment.

?

Test your settings.

In order to test if your configuration is correct, we create a J2EE project as a test.

Select File> New> Lomboz J2ee Project ..

Enter 'Test' as the project name and click Next.

Check your settings here; if your compilation path is 'test / src' and the default output path is 'Test / bin' there is no problem.

Click the Libraries tab in the Project Creation Wizard.

Since this library under Eclipse 2.1 is not configured correctly.

So select it and remove it.

Now add a new library, choose Library> Add library ..> Select JRE SYSTEM LIBRARY> Click Next.

Select the default library, click Finish.

The new library is configured.

Note: Because Eclipse 2.1 has a bug, you have to repeat this step when you create a new J2EE project.

Press NEXT.

Select Web Module> Add ..> Enter module 'onlinebank'> OK.

Select EJB Module (Modules) Tags> Add ..> Enter 'MyBank'> OK.

Select Targeted Server> Add ..> 'JBoss

3.2.1 a

Ll '.

Note: 'JBoss

3.2.1 a

LL 'is not a file name, but we are used in the file' jboss321all.server 'for the server to configure the server. Below is some segments of the file.

Name = "jboss 3.2.1 all"

EjBModules = "True"

Press Finish.

You will see all of these directories and libraries under Test Engineering in Package Explorer.

The 'src' in the TEST project is used to store the package of the development of the EJB component and the directory of the servlets package source code.

The 'mybank' directory is your EJB module, and 7 files are as shown in the following figure.

The 'OnlineBank' directory is your web module. When you start, you have 7 files as shown below. This module's JSP page will exist in this directory.

Note: If you are interested in Ant (from Jakarta Project), then you should notice that both modules contain an Ant's 'build.xml' file for compiling applications.

Select Window> show View> Lomboz J2EE View of the top Directory.

TEST project will also appear in the Lomboz J2EE view, including two modules 'mybank' and 'OnlineBank' use JBoss

3.2.1

As a default server.

Ok, we started to create an EJB,

Select File> New> Lomboz EJB CREATION WIZARD.

Note: You can click Right-click Access Generation Wizard by Package Explorer's Test Engine. Select the New> Lomboz EJB Creation Wizard in the menu as previously described.

Adding a package called 'au.com.tusc'; you can also use other names. Add 'MySession' in the name. Select the Stateless Session EJB option. It will be the same as the following picture The .com.tusc 'package creates file' mysessionBean.java '.

Note: The name of the bean, the name of JNDI, and the type of beans in the file will be generated. Similarly, when the file name is generated, the name 'Mysession' will be automatically added to 'bean'. So please pay attention to the naming practice Because you only need to enter the name of the bean in the wizard. Don't add this word in the name, because the wizard will automatically add it for you.

Now we have to add a business approach by wiping.

Select 'MySessionBean.java' in 'Package Explorer' and expand it, right click on the 'MySessionBean' node, select New> Lomboz EJB Method Wizard.

In Method Signature Enter 'PUBLIC STRING Learnj2ee (String Messg)', the type of method selection 'business method' and the type of interface selects 'Remote Interface'.

Signature, which is required by your business method in your bean class will be generated.

Add this line of Return "ME TOO!" In this method;

Code fragment in the bean file

? / **

? * @ ejb.interface-method

? * tview-type = "remote"

? *

? ** /

???? public? String Learnj2ee? (STRING Messg)? {

???????? Return "ME TOO!";

????}

Save this file. Now let's generate the rest of the rest of this bean (with HOME and remote interface with helping classes).

First join this bean to the module.

Select Package Explorer> Test> MySessionBean.java> MysessionBean, right-click on the above; a menu will pop up. Select the Lomboz J2EE item in the pop-up menu and select 'Add Ejb To Module'.

Select Package Explorer> Test> MyBank (this is a directory), right-click on it; a menu will pop up. Category and other related files; the deployment descriptor (deployment descriptor).

This will generate a directory called EJBSRC, which has a package called au.com.tusc, and the remote and local interfaces that are accompanied by the necessary help classes below.

Note: You don't have to edit any files generated by the xdoclet in the 'EJBSRC' directory using this tutorial. Because whenever you use the Generate EJB CLASSES, it generates the necessary interfaces and help classes mentioned above. After parsing the Bean class created by the Lomboz Bean Create Wizard, these files are generated by xdoclets. XDoclet reads (Looks AT) Declare the various tags and methods declared in the bean class, then generate the corresponding file. So you As long as you add a business method and implement them in the Bean class, the rest is handed over to the XDoclet. Therefore, you don't have to (nor!) Edit any generated file. This is in the process of reading this tutorial Come becomes more and more clear.

There are now 15 files in myBank> Meta-INF directory, including EJB-JAR.XML and JBOSS.XML and EJB-generate.xml. The foregoing mentioned that only 6 files in the first place. Other files are deployed beans Need to do. Now we will deploy this bean without any more information about deployment.

In the Lomboz J2EE view of your workspace (Workspace), expand TEST> Expand MyBank.

Add Au.com.Tusc.MysessionBean into your MyBank EJB module.

In JBoss

3.2.1 a

The LL icon is right-click as shown below.

A menu will pop up; select the debug server option. It will display the information shown in the CONSOLE of the Workspace after starting successfully after starting successfully.

Select Lombo J2EE View> Expand Test> Select MyBank and right click on it; a menu will pop up; select the deploy item.

Once this bean is deployed, a message will be confirmed in your 'Console', as shown below.

Now let's create a client to access beans deployed on the JBoss (Application Server).

Go to Package Explorer> Test> SRC, right-click on that, pop up a menu> Select EJB Test Client.

Enter the name of the package 'Test' and the client's name 'client'.

Select EJBHOME as 'MySessionHome' and EJB Interface as 'MySession'> Finish as shown below.

Now that the client has generated, it is time to call deployment Bean.

We need some code to call the bean method.

Add the following 'TestBean () method in Client.java.

String Request = "I'm Tired of 'Hello, World' Examples ..";

System.out.println ("Request from Cliant:" Request);

System.out.println ("Message from Server:" MyBean.Learnj2ee (Request);

CLIENT.JAVA code snippet.

Public void testbean () {

Try {

Au.com.tusc.mysession mybean = gethome (). CREATE ();

// --------------------------------------

// this is the place you make your caver

//System.out.println (MyBean.callyourthod ());

String Request = "I'm Tired of 'Hello, World' Examples ..";

System.out.println ("Request from Cliant:" 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 ();

}

}

Click this icon in the top menu as in Package Explorer.

Select> Run as> Java Application in this icon.

Your client will issue a request, and its result will be displayed in the console of your workspace, as shown below.

Note: Ignore these exceptions related to org.apache.log4j.property because it requires 'log4j.properties' on the client path. We will mention this issue later because it does not affect this bean function.

?

You have successfully created a bean and execute it. Now, before we start this learning case, we will summarize the concept of J2EE in the next chapter.? Will be in me BLOG: RAXY.BLOGBUS.COM Synchronous logout,

转载请注明原文地址:https://www.9cbs.com/read-115920.html

New Post(0)