Create a folder for your workspace. In this particular case, I have created a folder called “MyJ2EEWS” in my windows D drive.
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.
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)
In this tutorial, I am using a little icon on the left hand side of Resource as shown in the diagram below.
When you click on that little icon, it will come up with a list. Select “Other…”
Click on Show All check box.
After you have clicked on “Show all” check box, it will populate with new items in the list. Select J2EE.
Now you will get a J2EE Perspective in your workspace.
In this step, we will create a dynamic web project. I will span this step over ten sub steps
Click on File > New > Other
You will see a list of items in the new project wizard.
Select dynamic web project and click on Next
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.
Select a Jboss Server from the list and click on next.
A Dialog box will come up requesting for the Jboss Application server directory.
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.
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.
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.
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.
Write click on your WebContent directory as shown in the diagram and click on New > Other
Select ‘Servlet’ in the dialog box that comes up and press Next button.
• Provide the package name
• Provide the class name
• Check the “Generate an annotated servlet class” so that it creates some skeleton code for you
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.
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.
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.
This step will guide you editing your Servlet stub to do some work.
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.
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.
This step is about creating a Jboss Server and setting it up properly in order to deploy our application.
In Servers tab, right click on the empty location and choose New > Server as shown.
Choose Jboss Server and press next.
Provide Server properties like address, http port, JNDI Port , server configuration etc or just accept the default properties and click on Next.
Add your project to the server. Select the project from the Available projects and click on Add
Once the project has been added click on Finish.
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]
Once the server is started, test your application by accessing it in the browser.
Originally posted 2010-04-12 15:07:11.