Step 1:
Create a folder for your workspace. In this particular case, I have created a folder called “MyJ2EEWS” in my windows D drive.

Step 2:
Open the workspace in Eclipse. I am using IBM’s Rational Software Architect (RSA). Since this is built upon eclipse, you should be able to find these steps pretty similar.

Step 3:
Once the workspace is open, change the perspective to J2EE. There are several ways to do this. One way is to use the menu Windows > Open Perspective > Other and then choose J2EE from the list (you might have to check “Show All” check-box to see J2EE in the list. I am explaining an alternative way to do this in 5 sub steps below. (Step 3a through step 3e)
Step 3a:
In this tutorial, I am using a little icon on the left hand side of Resource as shown in the diagram below.

Step 3b:
When you click on that little icon, it will come up with a list. Select “Other…”

Step 3c:
Click on Show All check box.

Step 3d:
After you have clicked on “Show all” check box, it will populate with new items in the list. Select J2EE.

Step 3e:
Now you will get a J2EE Perspective in your workspace.

Step 4:
In this step, we will create a dynamic web project. I will span this step over ten sub steps
Step 4a:
Click on File > New > Other

Step 4b:
You will see a list of items in the new project wizard.

Step 4c:
Select dynamic web project and click on Next

Step 4d:
In the dialog box that appears, provide your Project Name. I have renamed my project as MyEnterprise.
On the same dialog, you can provide the target runtime which is nothing but your application server. To do so, click on the new button next to “Target Runtime” as shown in the diagram below.

Step 4e:
Select a Jboss Server from the list and click on next.

Step 4f:
A Dialog box will come up requesting for the Jboss Application server directory.

Step 4g:
Select the Jboss installation location. In my case the Jboss was installed in the following folder:
C:\JBoss Servers\My J2EE JBoss\jboss-4.0.1sp1 (This is a folder one level up from your ‘bin’ directory of Jboss.) After browsing the directory, click on Finish button.

Step 4h:
You will see that the target runtime for Jboss now appears in the drop down. Click on next.

Step 4i :
Click next on the dialog box that appears. You will see that ‘Java’ and ‘Dynamic Web Module’ project facets have been selected. Select them, if they are not. You can change the version of Java by clicking on the version number and selecting the proper version from the drop down if needed. Click on Next when you are done.

Step 4j:
You now will come up with a dialog box where you can configure your web module settings. If you would like to accept the default one, click on next. But you can modify the values as required. In my case, I wanted to change the context root to ‘myapp’ so I modified the first entry accordingly.
Press the Finish Button when you are done.

Step 5: Creating A Servlet
I have divided the process of creating servlets into 6 sub steps.
Step 5a:
Once you are done creating the Dynamic web project, you will see you workspace something similar to below. If not open the project explorer and see the folder structure. It will be something comparable.

Step 5b:
Write click on your WebContent directory as shown in the diagram and click on New > Other

Step 5c:
Select ‘Servlet’ in the dialog box that comes up and press Next button.

Step 5d:
• Provide the package name
• Provide the class name
• Check the “Generate an annotated servlet class” so that it creates some skeleton code for you

Step 5e:
If you want to provide a different URL mapping, you can do so here. You can even pass the initialization parameters if any. The information here will be used to create WEB.XML file. Click on next.

Step 5f:
In the next screen that comes up you can select different servlet properties and method stubs to be created. Once you are done, press Finish Button.

Step 6:
The Servlet Mapping – With actions taken in step 5 above, you will find a web.xml file updated with the servlet created. The following is a servlet mapping in my workspace and is available at the location given below.
MyEnterprise>WebContent>WEB-INF>web.xml

Step 7:
This step will guide you editing your Servlet stub to do some work.
Step 7a:
Open your servlet that you created. Since I clicked on “Generate an annotated servlet class” while creating a servlet and chose some methods that needed to created, my auto generated servlet stub looks like below.

Step 7b:
Edit your servlet to print some sample stuff. Since there are two methods I generated viz. doGet and doPost, I am forwarding any get request to doPost methods. In the doPost methods, I am writing some text using HttpServletResponse object’s writer.

Step 8:
This step is about creating a Jboss Server and setting it up properly in order to deploy our application.
Step 8a:
In Servers tab, right click on the empty location and choose New > Server as shown.

Step 8b:
Choose Jboss Server and press next.

Step 8c:
Provide Server properties like address, http port, JNDI Port , server configuration etc or just accept the default properties and click on Next.

Step 8d:
Add your project to the server. Select the project from the Available projects and click on Add

Step 8e:
Once the project has been added click on Finish.

Step 9:
Start The Jboss Server – Right click on the Jboss Server in the servers tab and click on start.
[Note: you have to add tools.jar (from jdk lib folder e.g. C:\j2sdk1.4.2_12\lib) in the Jboss class path. For that you need to double click on the server and click on “Open Launch Configuration” and then add the above jar in the Classpath tab]

Step 10:
Once the server is started, test your application by accessing it in the browser.


Originally posted 2010-04-12 15:07:11.