JBoss Meets Eclipse: Introducing the JBoss-IDEThe wildly popular J2EE application server goes from full steam to mainstream with a GUI-based IDE that plugs into the Eclipse development framework.
by
Javid Jamae
|
|
JBoss, the open source, J2EE-based application server, has been a favorite
of the Java community for a long time. But recently JBoss got a handy new
toolkit, thanks to Eclipseone that may just help the product go from
full steam to mainstream.
While JBoss has always been applauded for being robust and scalable, with support for security, load balancing, clustering, and transactional capability, what it hasn't had is a GUI-based IDE. And that has left the mass marketplace solely in the hands of closed source competitors such as IBM, BEA, and Borland. Those who prefer can always continue to configure JBoss using command line tools, but thanks to the Eclipse project, JBoss has an IDE that plugs into the Eclipse development framework, making the product a legitimate option for the thousands of developers who prefer a GUI. A few Eclipse plugins already have support for JBoss, but the JBoss-IDE plugin is by far the easiest to install, update, and use. The plugin supports starting and stopping servers, debugging server-side code, packaging archive files, and deploying archive files. It also has support for XDoclet code-generation. Best of all, the JBoss-IDE is developed and maintained by JBoss Inc., the makers of the JBoss Application Server itself In this article, I'll show you how to install and configure the JBoss-IDE plugin and then walk you through the steps of creating a simple Hello World application, packaging it, and deploying it to a JBoss server.
Installing the Plugin
Eclipse 2.x
|
Adding the Shortcuts to the Top Menu The JBoss-IDE plugin provides a set of buttons to start, stop, and terminate a server, as well as view the server console and log files. These buttons only operate on a single server that you define as a Default Server. Configuring the Default Server will come later; for now, here's how to make the buttons visible on the toolbar:
Eclipse 2.x
Configuring and Launching a Server In order to start your JBoss server, you must create a Debug Configuration. Running JBoss in a Debug Configuration allows you to set and use breakpoints in your server code. Go to Run>Debugand you should see several new "JBoss" Configurations in the left pane. Click on the one that matches the version of JBoss that you are running. The Debug option on the right allows you to define which perspective Eclipse will switch to when you launch your JBoss server. I prefer not having Eclipse change perspectives when my server starts, so I change it from Debug to None.
After defining the perspective, click New to create a new instance of your JBoss configuration. Give your configuration a name and point it to the home directory for your JBoss server (see Figure 1). Click on Close and then go to Window>Preferences>JBoss IDE>Launcher. You'll need to designate a Default Server so that you can use the buttons that we added to the top tool bar earlier (see Figure 2). After you click OK, you should be able to use the buttons that were added to the top tool bar earlier.
|
Now to learn how to use the plugin, you'll create a simple "Hello World!" Servlet and deploy it to JBoss. Put your source code (.java files) in a source folder and your compiled classes (.class files) in an output folder. Follow these steps to configure your source and output folders (Figure 3).
Next, you need to set your CLASSPATH by defining the libraries (JAR files) that Eclipse should use to compile your code. You also need to add a JAR file that will allow you to compile a Servlet. Luckily, Eclipse comes equipped with a Tomcat plugin, which contains the library you will need you to compile a servlet.
Follow these steps (see Figure 4):
Now, create a class called HelloWorldSerlvet in the com.devx.example package, using the following code in your servlet:
Next, you need a deployment descriptor so that JBoss will know how to access your Servlet. The deployment descriptor (web.xml) goes under a folder called WEB-INF in the .war file. Create a folder under src called WEB-INF. Then, create a file called web.xml in that folder, using the following source.
After all is said and done, your project structure should look like Figure 5.
|
Setting Up the Packaging Configuration Before you can deploy your application to JBoss, you need to define the structure of your WAR file through a Packaging Configuration, which you then run to create a WAR file.
Here's how to create a Packaging Configuration:
Click OK and you should see a file in your project called packaging-build.xml.
Creating and Deploying the WAR File Right click on the WAR file, select Deployment, and then Deploy To. You will see a Target Choice dialog appear, allowing you to select which application server you would like to deploy to, as shown in Figure 7.
I have JBoss 3.2.2 and JBoss 3.2.3 configured on my machine, thus both servers are available. After selecting the target you wish to deploy to, you should see a dialog that confirms that the application was deployed. Now, pull up your Web browser and try it out. Go to http://localhost:8080/helloworld/Hello, as shown in Figure 8. In this article, you learned how to install the JBoss-IDE plugin in Eclipse. You also learned how to configure a JBoss server and how to package and deploy a simple application that server. Keep a lookout for a follow-up to this article in which I will show you how to use the XDoclet features of the JBoss-IDE plugin.
Javid Jamae is the president of Jamae Consulting, a software development and consulting firm that provides business, training, and development services to large and small companies. Reach him by e-mail here.
|