Categories

Archives

Configuring Eclipse to Run Tomcat with WebORB

This post documents a pre-requisite step for the JavaScript Integration Course, but it is also useful if you’re doing Java development with Eclipse and WebORB. The instructions in this post will help you configure your development environment so you can develop Java services with Eclipse and have them deployed into Tomcat. Once deployed, your Java services can be consumed (methods can be invoked) by any client supported by WebORB, that is JavaScript, iOS, Android, Flex/AIR, Flash and Silverlight.

To get started, make sure to download and install Eclipse IDE for Java EE Developers. Also, you will need an installation of WebORB for Java. When you download WebORB, you get an installer packaged as a JAR file. Make sure to run the installer and accept all the default settings in the installation. Finally, install the Tomcat server. This post assumes you have the latest version of Eclipse (Eclipse Juno v. 4.2), Tomcat 7.0 and WebORB version 5, however, the instructions are applicable to the older versions of the software as well.

Registering Tomcat as s Server

Locate buy cheap cialis the “Servers” tan in Eclipse and define a new server using the wizard:

In the “New Server Wizard”, expand the “Apache” node and select “Tomcat 7.0 Server” as shown below:

Click “Next >”. In the next step you need to specify the location of your Tomcat 7 installation. Click the Browse button and locate the root directory of the Tomcat installation:

Click “Finish” to complete the Tomcat configuration. The server should appear in the Servers tab as shown below:

Configuring a Web Project

The next step is to configure an Eclipse project. The project will contain the code for the services which will be deployed into Tomcat/WebORB. From the Eclipse’s main menu select File > New > Dynamic Web Project. Assign the name to the project (these instructions assume the project name is PhonebookService. Also make sure the target runtime is “Apache Tomcat v7.0″ (the server runtime was configured in the previous step). Finally, make sure “Default Configuration for Apache Tomcat v.7.0″ is selected in the drop down box in the Configuration section:

Click “Next >”. There are no changes in the next step, so click “Next >” again. Click the “Generate web.xml deployment descriptor” checkbox:

Click “Finish” to finalize project creation.

Adding WebORB to the Project

To streamline the development WebORB should be added to the project and become a part of the web application. Adding WebORB to the project consists of three to four simple steps:

  1. Register WebORB servlet.
  2. Add configuration files.
  3. Add WebORB jar file.
  4. Add WebORB Console (optional, but highly recommended).

Register WebORB servlet

Locate and expand the WebContent folder in the project’s structure in Project Explorer. The folder should have the web.xml file which is a deployment descriptor for the web application. Right-click the file and select Open With > Text Editor. Eclipse opens the file for editing. Make sure to modify the file to look as shown below:

&lt;br /&gt;<br />
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;<br />
&amp;lt;web-app xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns=&amp;quot;http://java.sun.com/xml/ns/javaee&amp;quot; xmlns:web=&amp;quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&amp;quot; xsi:schemaLocation=&amp;quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&amp;quot; id=&amp;quot;WebApp_ID&amp;quot; version=&amp;quot;3.0&amp;quot;&amp;gt;&lt;br /&gt;<br />
  &amp;lt;display-name&amp;gt;PhonebookService&amp;lt;/display-name&amp;gt;&lt;br /&gt;<br />
  &amp;lt;listener&amp;gt;&lt;br /&gt;<br />
    &amp;lt;listener-class&amp;gt;weborb.ORBServletContextListener&amp;lt;/listener-class&amp;gt;&lt;br /&gt;<br />
  &amp;lt;/listener&amp;gt;&lt;br /&gt;<br />
  &amp;lt;servlet&amp;gt;&lt;br /&gt;<br />
    &amp;lt;servlet-name&amp;gt;weborb&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;<br />
    &amp;lt;servlet-class&amp;gt;weborb.ORBServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;<br />
    &amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;&lt;br /&gt;<br />
  &amp;lt;/servlet&amp;gt;&lt;br /&gt;<br />
  &amp;lt;servlet&amp;gt;&lt;br /&gt;<br />
    &amp;lt;servlet-name&amp;gt;download&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;<br />
    &amp;lt;servlet-class&amp;gt;weborb.DownloadServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;<br />
    &amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;&lt;br /&gt;<br />
  &amp;lt;/servlet&amp;gt;&lt;br /&gt;<br />
  &amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;<br />
    &amp;lt;servlet-name&amp;gt;weborb&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;<br />
    &amp;lt;url-pattern&amp;gt;*.wo&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;<br />
  &amp;lt;/servlet-mapping&amp;gt;&lt;br /&gt;<br />
  &amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;<br />
    &amp;lt;servlet-name&amp;gt;download&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;<br />
    &amp;lt;url-pattern&amp;gt;/codegen.wo&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;<br />
  &amp;lt;/servlet-mapping&amp;gt;&lt;br /&gt;<br />
  &amp;lt;welcome-file-list&amp;gt;&lt;br /&gt;<br />
    &amp;lt;welcome-file&amp;gt;weborbconsole.html&amp;lt;/welcome-file&amp;gt;&lt;br /&gt;<br />
    &amp;lt;welcome-file&amp;gt;index.html&amp;lt;/welcome-file&amp;gt;&lt;br /&gt;<br />
    &amp;lt;welcome-file&amp;gt;index.htm&amp;lt;/welcome-file&amp;gt;&lt;br /&gt;<br />
    &amp;lt;welcome-file&amp;gt;index.jsp&amp;lt;/welcome-file&amp;gt;&lt;br /&gt;<br />
    &amp;lt;welcome-file&amp;gt;default.html&amp;lt;/welcome-file&amp;gt;&lt;br /&gt;<br />
    &amp;lt;welcome-file&amp;gt;default.htm&amp;lt;/welcome-file&amp;gt;&lt;br /&gt;<br />
    &amp;lt;welcome-file&amp;gt;default.jsp&amp;lt;/welcome-file&amp;gt;&lt;br /&gt;<br />
  &amp;lt;/welcome-file-list&amp;gt;&lt;br /&gt;<br />
&amp;lt;/web-app&amp;gt;&lt;br /&gt;<br />

Add Configuration Files

Right-click the WEB-INF folder under WebContent in the project structure and select New > Folder. Type “flex” for the folder name and click Finish. Eclipse creates a new folder under WEB-INF. Right click the new flex folder and select the Import menu option. In the Import window that appear select File System under General. Click “Next >” to continue. Click Browse and navigate to the WebORB installation directory. From there navigate further to webapp/WEB-INF/flex and click “Open”. Select all the files as shown below and click “Finish”.

The next step is adding the main WebORB configuration files. The files will eventually reside in the WEB-INF/classes directory of the deployed web application, but since eclipse rewrites that directory every time when it runs Tomcat, the files must be placed into the “src” folder.

Locate and expand the “Java Resources” node in the root of the project structure. Right click the “src” node and select the “Import” menu item. Select “File System” under “General” and click “Next >”. Click “Browse” and navigate to the WebORB’s installation directory. From there navigate further to webapp/WEB-INF/classes and click “Open”. Select weborb-config.xml and weborb-acl.xml as shown below and click “Finish”:

Add WebORB Jar file

In the minimal deployment WebORB requires only one jar file – weborb.jar. Additional jar files should be added by following the same steps depending on the functionality used by the services and/or WebORB. The example reviewed in this post connects to a MySQL database, therefore two jar files will be added – weborb.jar and the mysql database driver library.

Locate and right-click the lib node under WebContent\WEB-INF node in the project structure. Select the “Import” menu item. Select “File System” under “General” and click “Next >”. Click “Browse” and navigate to the WebORB’s installation directory. From there navigate further to webapp/WEB-INF/lib. Click “Open” and select “mysql-connector-java-5.1.13-bin.jar” and “weborb.jar” as shown below. Click “Finish” to import the files.

Add WebORB Console (optional, but recommended)

Right-click the WebContent node in the project structure. Select New > Folder and create a folder “console”. Right click the newly created “console” folder and select the “Import” menu item. Select “File System” under “General” and click “Next >”. Click “Browse” and navigate to the WebORB’s installation directory. From there navigate further to the “webapp/console” directory. Select all the files as shown below and click “Finish”.

Finally import “weborbconsole.html” from [WEBORB INSTALL DIR]/webapp/ into the WebContent node in the project structure (the import steps are the same as described earlier).

Once all the configuration, JAR and console files are added, the project structure should look as shown below:

Adding Web Application to Tomcat

At this point the project contains the minimally required configuration for WebORB. In order to deploy the project into the Tomcat server configured at the beginning of this post, locate and right-click “Tomcat v7.0 Server at localhost” in the Servers tab. Select the “Add and Remove” menu option:

In the “Add and Remove” window select “PhonebookService” in the “Available” column and click “Add >” to move it to the “Confgured” column as shown below. Click “Finish” to continue.

Adding Java Service

To add a Java service to the project locate and right-click the “src” node under “Java Resources”. Select the New > Package menu item and enter com.tmc.blog for the package name. The next step is add to a class to the package. This post uses the Java Backend Service provided in the JavaScript Integration Course post. Right-click the com.tmc.blog node and select the New > Class menu item. Enter Phonebook for the class name and click “Finish” to finalize class creation. Replace the contents of the created class with the  code from the Java Backend Service post.

Running Tomcat and WebORB

Click the “Start the server” button (green circle with a white triangle) in the “Servers” tab. Eclipse launches an instance of Tomcat and deploys the PhonebookService web application into it. You should see the logging output from WebORB as well in the “Console” tab. Once Tomcat starts, open a browser and enter http://localhost:8080/PhonebookService/weborb.wo to open the WebORB Management Console. Once the console starts up, select the Services tab in the WebORB Management Console, expand the WEB-INF/classes node and navigate to the Phonebook service (you will need to expand the “com”, “tmc” and “blog” nodes as well). The Phonebook node represents the class with the same name and contains the methods of the class. Expand the Phonebook node and click the “createListing” method. Enter values for the “name” and “phonenumber” arguments and click “Invoke”. The console invokes the method via WebORB and the service creates a record in the database (see the service’s code for details). Now you can click the “getListings” node and click Invoke. The console invokes the method and displays the results of the method invocation.

The subsequent post will review other development/deployment options, for instance, developing with IntelliJ IDEA and deploying into the standalone version of WebORB. After that, the series will continue with the development of the JavaScript client for the Phonebook service.

cvs Zanaflex

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free