PYTHON  
 
  Oracle Forms & PL/SQ  
 
  ROR  
 
  Java  
 
  php  
 
  ask us  
 
  home  
 

 

Web Technologies






JBoss J2EE in Eclipse

JBoss J2EE in Eclipse


1. Installing JBoss:

The programs Jboss present in the Eclipse IDE  
do not contain all the properties, mainly to 
define doclets. We need to install JBoss software.
Go to:
 sourceforge.net
Choose the jboss-4.0.5.GA.zip version Go to: Choose the installer: 1.2.1.CR4.zip version Unzip the firs, then the second file inside any directory. Jboss is installed in the directory: C:\Program Files\jboss-4.0.5.GA Set the Jboss home directory: JBOSS_HOME C:\Program Files\jboss-4.0.5.GA Go to: C:\Program Files\jboss-4.0.5.GA click on run.bat

2. Configuration JBoss in Eclipse

Configuring the JBoss server: 
- Lanch Eclipse JBoss IDE
- Set a new Work place (as C:\Eclipse\JBoss)
- Click on the debug shortcut (green chip),
- Select Debug
- Set Name (any) : Jboss-4.0.5.GA
- Click on Home

Setting JBoss 4.0.x Home Directory:
- Browse to find C:\Program Files\jboss-4.0.5.GA
- Server Configuration: Default
- Click Apply

3. Building a project: The Factorial project: Jboss1Example

Follow the steps:

step 1

Create a new J2EE 1.4 Project. 
New > Project and choose 
JBoss-IDE > J2EE Projects > J2EE 1.4 Project > Next

fill in the project name:
Jboss1Example > Next

Create source folder: src

fill in output default folder (with subdirectory: bin): 
Jboss1Example/bin
> Finish
The package Explorer will contains the J2EE 1.4 core classes.


step 2 

We will create an EJB bean:
Select File > New > Other...  
Choose JBoss-IDE > EJB Components > Session Bean > 
Next
Fill in:
Package: Jboss1Example.ejb
Name: FactorialBean
(the class name)
Other buttons are checked, mainly ejbCreate() method.
>Finish
The class is then created: take a look at package Explorer.

step 3

Right-click the FactorialBean class, under the 
FactorialBean Java file. 
In the J2EE menu. Select J2EE > Add Business Method.

In the method wizard, enter:
Method name: theFactorial
Return type: double[]  
Parameters: 
	name: numbers 
	type: int 
>Finish.
The method theFactoial has been added to FactorialBean class.


step 4

We ant to compute the factorials. The related method will be defined 
by the function theFactorial() as:
public double[] theFactorial(int numbers) { if (numbers < 0) { throw new EJBException("Argument should be positive"); } double[] suite = new double[numbers + 1]; suite[0] = 1; if (numbers == 0) { return suite; } suite[1] = 1; for (int i = 2; i <= numbers; i++) { suite[i] = i* suite[i - 1]; } return suite; }
step 5 We will run then XDoclet on the following file to generate the EJB interfaces: step 6 To generate the related EJB classes and descriptors, we will create some XDoclet configurations that run against the project. Click on Package Explorer > file > Properties Select XDoclet configurations. > Check-box Enable XDoclet at the top of the page. Creating a new generation configuration named EJB. > Right-click in the upper area to pop-up the menu and choose Add. Type EJB in the dialog and click OK. step 7 Configuration ejbdoclet - Select the EJB configuration. - In the lower-left area, right-click to popup the menu and choose Add Doclet. - A list of available doclets will appear. Choose ejbdoclet and click OK. - On the lower-right area, we have the properties of the ejbdoclet. -- Check the destDir property; double-click and set it to src -- Check ejbSpec ; double-click and set it to 2.0. This configuration produces an ejbdoclet that will produce files in src folder and for the EJB 2.0 specifications. step 8 Configuring Fileset - In the lower-left area, right-click on ejbdoclet to popup the menu and choose Add. - A list of available subtasks will appear. Choose fileset and click Ok. - On the lower-right area, we have the properties of the fileset. -- Set the dir property to src. -- Uncheck excludes -- Set the includes property to **/*Bean.java The configuration produces an ejbdoclet with a fileset that contains the src directory, and all files under it that end in Bean.java. step 9 Deploying Descriptor Configuration: Right-click on ejbdoclet and add a new deploymentdescriptor. - Set the destDir property to src/META-INF. All of the standard EJB deployment descriptors will now be placed in the src/META-INF directory. step 10 Configuring JBoss: Right-click on ejbdoclet and add jboss subtask. -- Set the destDir property to src/META-INF. -- Set the Version property to 3.0. All of the JBoss-specific deployment descriptors will now be placed in the src/META-INF directory. step 11 Configuring Package Substitution: Right-click on ejbdoclet and add packageSubstitution subtask. -- Set the packages property to ejb. -- Set the substituteWith property to interfaces. This will place our generated EJB interfaces in the Jboss1Example.interfaces java package. step 12 Configuration of the Interface: - Right-click on ejbdoclet and add a new remoteInterface subtask. - Right-click on ejbdoclet and add a new homeInterface subtask. These subtasks will generate the EJB home and remote interfaces. step 13 - Click OK to save the XDoclet configuration for the Jboss1Example. - Right-click on the Jboss1Example project and select Run XDoclet. The XDoclet generation will display its output in the console. The output should look like this: xdoclet-build.xml
Select the project and refresh it (you can press F5). step 14 We will write a servlet that access the built EJB to compute the Factorial suite. At left: > Click on Package Explorer and click on New > Choose HTTP Servlet > Next step 15 Configuring HTTP Servlet: -- Set the Package to Jboss1Example.web -- Set the Class Name to ComputeServlet -- Check the init() method -- Check the doPost() method > Finish -> ComputeServlet.java appears. This servlet needs some initialization and processing code. We will insert the missing XDoclet tags for the Servlet. In the Javadoc class paragraph and complete with: * *@web. */ype “@web.” Press CTRL+Space to JBoss Eclipse IDE's auto-completion in action. The related file is then: ComputeServlet.java
step 16 16.1. Generating the Servlet related files: To generate the Web descriptors, we will create another XDoclet configuration, like we did for our EJB. XDoclet Web Configuration Creation -- Edit the project properties. Right-click on the project and select Properties. -- Select XDoclet Configurations. -- Right-click in the top area to pop-up the menu and choose Add. Type Web in the dialog and click OK. We have created a new generation configuration named Web. 16.2. Configuring Webdoclet: - Select the Web configuration. - In the lower-left area, right-click to popup the menu and choose Add Doclet. - A list of available doclets will appear. Choose webdoclet and click OK. - On the lower-right area, set the destDir property to src/WEB-INF. This configuration contains a webdoclet that will produce files in the src/WEB-INF folder. 16.3. Configuring Fileset: - In the lower-left area, right-click on webdoclet to popup the menu and choose Add. - Choose fileset and click Ok. - On the lower-right area, you see the properties of the fileset. -- Set the dir property to src. -- Uncheck excludes -- Set the includes property to **/*Servlet.java. This configuration now contains a webdoclet with a fileset that contains the src directory, and all files under it that end in Servlet.java 16.4. Configuring Deployment Descriptor: Add a new deploymentdescriptor subtask to the webdoclet. Set the Servletspec property to 2.3. All of the standard Web deployment descriptors will now be placed in the src/WEB-INF directory (property is inherited from webdoclet). 16.5. Configuring JBoss: Add a new jbosswebxml subtask to the webdoclet, Set the Version property to 3.0. All of the JBoss-specific Web deployment descriptors will now be placed in the src/WEB-INF directory (property is inherited from webdoclet). Click OK to save the XDoclet configuration for the Jboss1Example. Right-click on the Jboss1Example project and select Run XDoclet. The XDoclet generation will display its output in the console is: xdoclet2-build.xml
step 17 Now, we want to run our servlet, we'll create an HTML page that passes it parameters. - Create a docroot folder under the root of the project Select the project: Jboss1Example > File > New > Folder > Folder Name : docroot - Create an empty file named index.html under the docroot folder: right-click on docroot > New > File> Fill in File Name : Index.html The index.html file is intended to be the default page for the Web application and contains a form that will be posted to the Servlet. index.html
step 18 The J2EE Application We will create some additional files. -- select New > Descriptors >EAR 1.3 Deployment Descriptor > Next Make sure application.xml is the name of the file, and click Finish The META-INF directory contains now the application.xml file. -- Select application.xml -- Right-clic and choose text editor. Its content is: application.xml
step 19 Configuring the packaging of archives. To create a J2EE application, packaging configurations will be defined: - The EJB JAR. It will contain the EJB classes, EJB interfaces, the ejb-jar.xml and jboss.xml deployment descriptors. - EJB Client JAR. It will contain the EJB interfaces. - Web Application WAR. It will contain the Servlet class, the EJB client Jar, and the web.xml deployment descriptors. - The J2EE Application EAR. It will contain : 19.1. Enable Packaging: - Select the project > Properties - Select Packaging Configurations. - Check the check-box labeld Enable Packaging 19. 2. Creating the EJB JAR - Press add and type FactorialEJB.jar in the dialog and click OK. - We have created a new packaging configuration that will produce the FactorialEJB.jar file. We want to add the EJB classes and interfaces. Eclipse has generated the compiled classes into the bin folder (declared as the default output dir of the project). - Select the FactorialEJB.jar item - Right-click - Choose Add Folder - Click on Project Folder - Select the /Jboss1Example/bin folder - Click OK. To set just EJB classes and interfaces, the includes will be: jboss1Example/ejb/*.class,jboss1Example/interfaces/*.class - Click on OK 19.3. Adding the standard EJB deployment descriptor: - Select FactorialEJB.jar item - Right-click in the area to pop-up the menu and choose Add File. - Click on Project File - Select the /Jboss1Example/src/META-INF/ejb-jar.xml - click OK - Set the prefix to META-INF (ejb-jar.xml must be located under the META-INF directory of the EJB package) - Click on OK. 19.4.Adding a EJB deployment descriptor: -S elect the FactorialEJB.jar item, - Right-click in the area and choose Add File, - Choose is /Jboss1Example/src/META-INF/jboss.xml, (jboss.xml must be located under the META-INF directory of the EJB package), - Set the prefix to META-INF, - Click on OK. The packaging configuration for the FactorialEJB.jar is now complete.
step 20
FactorialWeb.war creation
***
Click the Add button, 
- Type FactorialWeb.war in the dialog,
- Click OK.
We have then a new packaging configuration 
that will produce the FactorialWeb.war file.

- Select the FactorialWeb.war item,
- Right-click in the area to pop-up the menu,
- Choose Add Folder,
- Click on Project Folder,
- Select the /Jboss1Example/bin folder,
- Set the include filter to jboss1Example/web/*.class,
(we only want the Servlet class. The classes must be 
located under the WEB-INF/classes of the War package.)
- Set the prefix to WEB-INF/classes,
- Click on OK.
	
To add the standard Web deployment descriptor:
- Select the FactorialWeb.war item,
- Right-click in the area to pop-up the menu,
- Choose Add File,
The file to choose is /Jboss1Example/src/WEB-INF/web.xml.
(The web.xml must be located under the WEB-INF of 
the War package),
- Set the prefix to WEB-INF,
- Click on OK.
	
To add the JBoss specific Web deployment descriptor:
- Select the FactorialWeb.war item
- Right-click in the area,
- Choose Add File, 
The file to choose is /Jboss1Example/src/WEB-INF/jboss-web.xml
The jboss-web.xml must be located under the WEB-INF of 
the War package. 
- Set the prefix to WEB-INF.
- Click on OK.
(See Remark *** below)

- Select the FactorialWeb.war item,
-Right-click in the area,
- Choose Add Folder,
- Click on Project Folder,
- Select the /Jboss1Example/docroot folder,
(This is the content of the Web Application.
- Click on OK.

The packaging configuration for the 
FactorialWeb.war is now complete.

step 21

FactorialApp.ear creation

- Click the Add button, 
- Type FactorialApp.ear in the dialog,
- Click OK.
(We have created a new packaging configuration that 
will produce the FactorialApp.ear file.)

To add the application deployment descriptor
- Select the FactorialApp.ear item 
- Right-click in the area 
- Choose Add File
The file to choose is /Jboss1Example/src/META-INF/application.xml.
The application.xml must be located under the META -INF 
of the EAR package. Set the prefix to META -INF.
- Click on OK.
	
To add the EJB module:
- Select the FactorialApp.ear item 
- Choose Add File
As the packaging has not been run yet, the file to choose:
/Jboss1Example/FactorialEJB.jar will be taped in the text 
field. 
- Click on OK.
	
To add the Webmodule: 
- Select the FactorialApp.ear, 
- Choose Add File,
As the packaging has not been run yet, the file to choose:
/Jboss1Example/FactorialWeb.war will be taped in the text 
- Click on OK.
	
The packaging configuration for 
the FactorialApp.ear is now complete.

Click OK to save the packaging configurations.

step 22 

- Right-click on the project,
- Select 
- Run Packaging,
That will display its output in the console. 
This output should look like this:
 FactorialApp.ear
step 23 Debugging the JBoss server: - Click on the debug shortcut (green chip), - Select Debug - Make sur that Jboss-4.0.5.GA is selected in the left directories of Configuration. - Click on Source > Add > java Project > > Select Jboss1Example > OK - Click on Debug The output is sent to the console. step 24 Deploying the project: run as debug run diclet and package deploy FactorialApp.ear Here are the result: The: Eactorial Form
and the Factorial Result

Remark:(***) Since we run JBoss 4.0.5.GA version (>4.0), we do not set package EJB interfaces in the WAR and EJB-JAR - client. This is due to the new features of Tomcat that rise a ClassLoaderException.


  
Google
Web
ScientificSentence
 



chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2011. All rights reserved.