WebSphere Application Server Tips

Running Standalone Client

This topic covers running a standalone client, i.e. outside the container.

To lookup an ejb in ejb.jar, as a minimum the following are required on the classpath:

  • ${LIB_PATH}/ejb.jar
  • ${WebSphereHome}/runtimes/base_v5/lib/namingclient.jar
  • ${WebSphereHome}/runtimes/base_v5/lib/ecutils.jar
  • ${WebSphereHome}/runtimes/base_v5/properties

If you're still getting problems, try adding the following:

  • ${WebSphereHome}/runtimes/base_v5/java/jre/lib/rt.jar
  • ${WebSphereHome}/runtimes/base_v5/lib/j2ee.jar
  • ${WebSphereHome}/runtimes/base_v5/lib/wsexception.jar

Simple code example

     public static void testLookup() {

          Hashtable properties = new Hashtable();
          properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");

          properties.put(Context.PROVIDER_URL, "iiop://localhost:2809/");

          try {
                TestSessionHome home = null;

                InitialContext context = new InitialContext(properties);

                Object objref = context.lookup("ejb/test/TestSessionHome");
                home = (TestSessionHome) PortableRemoteObject.narrow(objref, TestSessionHome.class);

                if (home != null) {
                    TestSession remote = home.create();             
                    if (remote != null) {
                         System.out.println("Remote returned: " + remote.getTestString());
          } catch (NamingException ex) {
              System.out.println("Exception: " + ex);
          } catch (RemoteException ex) {
              System.out.println("Exception: " + ex);
          } catch (CreateException ex) {
              System.out.println("Exception: " + ex);


If you're getting the following error, it is probably because your client code is being executed within the same jvm as the application server. E.g. Executing your client class within the WebSphere Application Developer test environment. Try executing it directly from the command line using something like Ant.

Apparently the gui version of JUnit results in the same problem. Again, execute JUnit from an Ant script.

If you're executing a client application or JUnit from Ant, make sure you've specified 'fork=true' for the Ant task.

java.lang.IncompatibleClassChangeError: com.ibm.CORBA.iiop.ORB method createObjectURL(Ljava/lang/String;)Lcom/ibm/CORBA/iiop/ObjectURL;
    at com.ibm.ws.naming.util.WsnInitCtxFactory.parseIiopUrl(WsnInitCtxFactory.java:1668)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.parseBootstrapURL(WsnInitCtxFactory.java:1427)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:368)
    at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:102)
    at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:408)
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:131)
    at javax.naming.InitialContext.lookup(InitialContext.java:359)

Example client DOS batch file

@echo off
SET WAS_HOME=d:\Program Files\ibm\WebSphere Studio\runtimes\base_v5
SET JAVA_HOME=d:\Program Files\ibm\WebSphere Studio\runtimes\base_v5\java
"%JAVA_HOME%\bin\java" -classpath ".;e:/tmp/ejb.jar;%WAS_HOME%\lib\namingclient.jar;%WAS_HOME%\lib\ecutils.jar;%WAS_HOME%\properties" com.cgey.afw.lookup.MyClient
echo on

Example Ant Script

<?xml version="1.0"?>

<project name="test_client" default="main" basedir=".">

  <property name="was.home.dir" value="d:/Program Files/ibm/WebSphere Studio/runtimes/base_v5"/>
  <property name="jvm.home.dir" value="${was.home.dir}/java"/>

  <target name="main">


Cleaning up the Workspace

A lot of temporary files etc. are created in the workspace. Trial and error suggests the following can be deleted. This has not be extensively proven. Close Application Developer first. Backup your files before-hand!

This is an Ant target extracted from a build script. You'll need to set properties for workspace.dir and workspace.metadata.dir.

Use at your own risk!

  <target name="CleanWorkspace" description="Removes all redundant files from Workspace">
     <delete quiet="false" failonerror="false" includeemptydirs="true">
         <fileset dir="${workspace.dir}" includes="orbtrc.*.txt"/>
         <fileset dir="${workspace.metadata.dir}" includes="LoggingUtil*.log"/>
         <fileset dir="${workspace.metadata.dir}/.plugins/com.ibm.etools.ejbdeploy" includes="ejbdeploy*.log"/>
         <fileset dir="${workspace.metadata.dir}/.plugins/com.ibm.etools.server.core" includes="**/*" excludes="server.log,factories.xml"/>
         <fileset dir="${workspace.metadata.dir}/.plugins/org.eclipse.core.resources/.history" includes="**/*"/>
         <fileset dir="${workspace.metadata.dir}/.plugins/org.eclipse.help" includes="**/*"/>
         <fileset dir="${workspace.metadata.dir}/.plugins/org.eclipse.jdt.core" includes="**/*.index"/>
     <delete quiet="false" failonerror="false" dir="${workspace.metadata.dir}/.plugins/org.eclipse.help.ui" />

Trouble Shooting

Server Definition Disappears

If your server definition appears to have disappeared, try running one of your beans with 'Run on Server'. This creates a new server and configuration, but also causes the missing server to re-appear.

You may get errors when the new server configuration is used. However, the old configuration should become visible again.

Publishing Server Fails

Publishing the server fails with an error messages similar to the following:

Creating folder .repository

The J2EE projects defined in the server configuration are not consistent with the projects that exist in the workbench: The module project "MyProject" in the EAR project "MyEar" is not defined in the server configuration. This problem can be resolved by opening an editor for the server "MyServer" or the server configuration "MyServerConfiguration" and then responding Yes to the WebSphere Server Warning window that appears.

This can be fixed by removing the enterprise application from the server configuration, removing the errant module from the enterprise application configuration, then adding them back in, as follows:

  1. Open the J2EE Perspective
  2. In the J2EE Hierarchy view, select the Enterprise Application, right click and select, 'Open With->Deployment Descriptor Editor'
  3. Select the 'Module' tab
  4. Select the errant module and click on the 'Remove' button.
  5. Save everything. (File->Save All)
  6. Open the server configuration view. E.g. From the main menu, select 'Window->Show View->Server Configuration'
  7. Save everything. (File->Save All)
  8. In the Server Configuration view, open up the tree to display the Enterprise Application
  9. Right click on the enterprise application and select 'Remove'
  10. Add the module back into the Enterprise Application by clicking on the 'Add' button and selecting the errant module.
  11. Select Finish.
  12. Using the 'Server Configuration' view, add the enterpise application by right clicking the server configuration and selecting 'Add->MyEnterpriseApplication'
  13. Save everything again.
  14. If prompted to 'Repair Server Configuration' select 'OK'
  15. Re-generate any stubs. E.g. Right click the EJB module and select 'Deploy and RMIC Code'.
  16. Right click the Enterprise Application and select 'Generate Deploy Code'.
  17. Re-publish and the server.
  18. Start the server.

If the problem still persists, you may need to try it again. Also try the following after backing up your work.

  1. Close Application Developer
  2. Delete the 'tmp?' folders under MyWorkspace\.metadata\.plugins\com.ibm.etools.server.core (see also Cleaning up the Workspace)
  3. Restart Application Developer

Note: This may subsequently cause the server definition to 'disappear'. See Server Definition Disappears.

Note: This doesn't always solve the problem. Make frequent backups of workspace and source tree!

Cannot Export EAR

When exporting an EAR file you get errors relating to a non-existent project try the following after backing up your work:

  1. Close Application Developer
  2. Using a text editor
    1. remove the guilty <project> element from /MyEar/.project
    2. remove the guilty <mappings> element from /MyEar/META-INF/.modulemaps
    3. remove the guilty <module> element from /MyEar/META-INF/application.xml
  3. Delete any backup files your text editor may have made
  4. Restart Application Developer

Table t1 (or q1) does not exist

You may get an error 'table xxx.t1 (or xxx.q1) doesn't exist' - Hell. Create one with any old column names and keep WebSphere happy! If you're using MySQL the command is:

create table t1 (dummy varchar(1));

Enterprise Application not showing up in Jar dependency editor.

Can be caused by duplicate entries in /MyEnterpriseApp/META-INF/.modulemaps. There should only be one entry. The ID must correspond with the ID of the entry in /MyEnterpriseApp/META-INF/application.xml.

  1. Close the workspace
  2. Manually edit the files to be consistent
  3. Restart the workspace

This doesn't always solve the problem! So far, only returning to backups fixes this!


See IndirectJNDILookup Error in WebSphereTutorial

Initial startup settings

These are set in the folder IBM/WebSphere Studio/wsappdev.ini

See also:

WebSphereTutorial, InitialContext

Frank Dean - 24 September 2003