Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Non-Debug compilations in WebSphere Studio Application Developer

Barry Searle, WebSphere Studio Application Developer Migration Team Leader, IBM Toronto Lab
Photo: Barry Searle
Barry Searle is the Migration Team Leader for WebSphere Studio Application Developer. He is a professional engineer who has worked at the IBM Toronto Lab for over ten years on various application development tools. Prior to that he had many years of industry experience developing command and control systems and leading complex communications development projects. You can reach Barry at searle@ca.ibm.com.
Ellen McKay, WebSphere Studio Application Developer Information Developer, IBM Toronto Lab
Photo: Barry Searle
Ellen McKay is an Information Developer for IBM Toronto Lab. She writes online help and publications for WebSphere Studio Application Developer. You can reach Ellen at ecmckay@ca.ibm.com.

Summary:  This article shows you how to create a GUI menu item to change the compilation mode dynamically (for your current session only). This article also describes an Ant task for setting the compilation debugging information level during production Ant builds (which run Application Developer "headless").

Date:  01 Jun 2002
Level:  Intermediate

Activity:  3407 views
Comments:  

Introduction

WebSphere® Studio Application Developer (hereafter called "Application Developer") compiles code with debugging information, but does not provide a way to compile code without debugging information. This article shows you how to create a GUI menu item to change the compilation mode dynamically (for your current session only). This article also describes an Ant task for setting the compilation debugging information level during production Ant builds (which run Application Developer "headless"), as described in the three-part article Using Ant with WebSphere Studio Application Developer.

The code in com.ibm.sample.javacDebugOnOff.zip that is provided below has been tested with Application Developer, Versions 4.0.2 and 4.0.3, and works as described, but may not work with future versions of the product. The code is not part of Application Developer and is not officially supported. Before downloading and using this code, you will be asked to read and accept a license agreement. If you have suggestions or encounter problems, please e-mail Barry Searle.


Control of compilation options by JavaCore class

If you browse the open source code for WebSphere Studio Workbench, you will discover it has a class, JavaCore, that controls how compilation happens. The JavaCore class acquires its startup default values from internally coded values within the class, and also has a setOptions method to dynamically change the compilation mode for the current session. However, any dynamically specified compilation settings using the setOptions method are not saved as a preference store and hence are not persistent between sessions -- on start up, the internal default values are always used. Making dynamic compilation settings persistent is being considered for future releases of WebSphere Studio Workbench, the platform on which Application Developer runs.


Menu option to dynamically change the compilation mode

Application Developer includes a Plug-in Development Environment (PDE) that you can use to develop a new workbench plug-in. You can use this facility (see the Application Developer online help for information on using it) and accept all the defaults to produce a simple JavacDebugOnOffPlugin, as shown below:

package com.ibm.sample.javacDebugOnOff;
import org.eclipse.ui.plugin.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.resources.*;
import java.util.*; 

/** The main plugin class to be used in the desktop. */
public class JavacDebugOnOffPlugin extends AbstractUIPlugin {
   //The shared instance.
   private static JavacDebugOnOffPlugin plugin;
   //Resource bundle.
   private ResourceBundle resourceBundle; 

   /** The constructor. */
   public JavacDebugOnOffPlugin(IPluginDescriptor descriptor) {
      super(descriptor);
      plugin = this;
      try {
         resourceBundle = ResourceBundle.getBundle(
            "JavacDebugOnOff.JavacDebugOnOffPluginResources");
      } catch (MissingResourceException x) {
         resourceBundle = null;
      }
   } 

   /** Returns the shared instance. */
   public static JavacDebugOnOffPlugin getDefault() {
      return plugin;
   } 

   /** Returns the workspace instance. */
   public static IWorkspace getWorkspace() {
      return ResourcesPlugin.getWorkspace();
   } 

   /** Returns the string from the plugin's resource bundle. */
   public static String getResourceString(String key) {
      ResourceBundle bundle=
         JavacDebugOnOffPlugin.getDefault().getResourceBundle();
      try { 
         return bundle.getString(key);
      } catch (MissingResourceException e) {
         return key;
      }
   } 

   /** Returns the plugin's resource bundle. */
   public ResourceBundle getResourceBundle() {
      return resourceBundle;
   }
}

You can then use the PDE to attach a menu item and two On/Off actions. The resulting plugin.xml file is shown below:

<?xml version="1.0" encoding="UTF-8"?>
<!-- File written by PDE 1.0 -->
<plugin 
   id="com.ibm.sample.javacDebugOnOff" 
   name="Javac Debug OnOff"version="1.0.0" 
   provider-name="IBM" 
   class="com.ibm.sample.javacDebugOnOff.JavacDebugOnOffPlugin">
   <requires>
      <import plugin="org.eclipse.core.runtime"/>
      <import plugin="org.eclipse.core.resources"/>
      <import plugin="org.eclipse.ui"/>
      <import plugin="org.eclipse.jdt.core"/>
   </requires> 

   <runtime>
      <library name="JavacDebugOnOff.jar">
         <export name="*"/>
      </library>
   </runtime> 

   <extension 
      id="com.ibm.sample.javacDebugOnOff"zzzzzz 
      name="Javac Debug OnOff Menu" 
      point="org.eclipse.ui.actionSets">
      <actionSet 
         label="Javac Debug OnOff Actions"
         visible="true"
         id="com.ibm.sample.javacDebugOnOff.actionSet">
         <menu
            label="Javac Debug OnOff"
            id="com.ibm.sample.javacDebugOnOff.menu">
            <separator
               name="separator1">
            </separator>
         </menu>
         <action
            label="Javac Debug OFF"
            tooltip="javac debug OFF"
            class="com.ibm.sample.javacDebugOnOff.WorkbenchWindowActionDelegateOff"
            menubarPath="com.ibm.sample.javacDebugOnOff.menu/separator1"
            id="com.ibm.sample.javacDebugOnOff.actionOff">
         </action>
         <action
            label="Javac Debug ON"
            icon="debugGEF.gif"
            tooltip="javac debug ON"
            class="com.ibm.sample.javacDebugOnOff.WorkbenchWindowActionDelegateOn"
            menubarPath="com.ibm.sample.javacDebugOnOff.menu/separator1"
            id="com.ibm.sample.javacDebugOnOff.actionOn">
         </action>
      </actionSet>
   </extension>
</plugin>

When you generate the On/Off actions, you only need to fill in the appropriate run method code. In our case, the code for the "On" action is inserted and the completed ActionDelegate "On" code is listed below. (The "Off" code has do not generate instead of generate.)

package com.ibm.sample.javacDebugOnOff;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jdt.core.JavaCore;
import java.util.Hashtable;

/** JavacDebugOnOff 'On' Action Delegate */
public class WorkbenchWindowActionDelegateOn implements 
   IWorkbenchWindowActionDelegate {
   IWorkbenchWindow activeWindow = null;

   /** The constructor. */
   public WorkbenchWindowActionDelegateOn()
   {;} 

   /** set compilation to debug 'On' */
   public void run(IAction arg0) {  
      Hashtable options = JavaCore.getJavaCore().getOptions();
      options.put("org.eclipse.jdt.core.compiler.debug.localVariable", 
         "generate");
      options.put("org.eclipse.jdt.core.compiler.debug.lineNumber", 
         "generate");
      options.put("org.eclipse.jdt.core.compiler.debug.sourceFile", 
         "generate");
      JavaCore.setOptions(options); 

      Shell shell = activeWindow.getShell();
      MessageDialog.openInformation(shell, "Action Debug On", 
         "Action Debug On was executed");
   }
   /** No selection action */
   public void selectionChanged(IAction proxyAction, 
      ISelection selection)
   {;} 

   /** No dispose action */
   public void dispose()
   {;} 

   /** Initialize activeWindow variable */
   public void init(IWorkbenchWindow window) {
   activeWindow = window;
   }
}

When you are done, create JavacDebugOnOff.jar containing the following classes, which you created while making the plug-in:

  • com\ibm\sample\javacDebugOnOff\JavacDebugOnOffPlugin.class
  • com\ibm\sample\javacDebugOnOff\WorkbenchWindowActionDelegateOff.class
  • com\ibm\sample\javacDebugOnOff\WorkbenchWindowActionDelegateOn.class

Now, all you have to do is create a new plug-in directory com.ibm.sample.javacDebugOnOff and put JavacDebugOnOff.jar and plugin.xml into it. Restart Application Developer and you will have a new menu item called Javac Debug On/Off to control your compilation mode for the current session. Or, you can save some time and just download the attached com.ibm.sample.javacDebugOnOff.zip code.

The new menu item will not automatically be visible. For each perspective where you want to access the new menu item, follow these steps:

  1. Switch to the desired perspective.

  2. Select Perspective => Customize. Expand Other and select JavacDebugOnOff. Click OK.

  3. Select Perspective => Save as. Accept the default value and click OK.


Ant task to dynamically change the compilation mode

The three-part article Using Ant with WebSphere Studio Application Developer describes how to create Ant tasks that run Application Developer "headless" to allow automated production builds. The download code for that article has been updated to include a new Ant task called setDebugInfo, which lets Ant builds dynamically control the debugging information generated during compilation. Please read those articles for details on using Ant with Application Developer.

The new setDebugInfo task enables an Ant build.xml script to contain commands such as:

<setDebugInfo /> 
<echo message="current compilation debug settings: ${DebugInfo}" />
   ... do builds here ...
<setDebugInfo LineNumber="false" LocalVariable="false" 
   SourceFile="false" />
<echo message="current compilation debug settings: ${DebugInfo}" />
   ... do builds here ...
<setDebugInfo DebugInfo="true" PropertyName="DebugInfoMsg" />
<echo message="current compilation debug settings: ${DebugInfoMsg}" />
   ... do builds here ...

The code will not be described in detail here, since it is very similar to the ProjectBuild Ant task described in Using Ant with WebSphere Studio Application Developer -- Part 3. In essence, it contains three true/false properties (LineNumber, LocalVariable, and SourceFile), which control their respective debug information (corresponding to the normal Java TM compile command javac options -g:{lines,vars,source}.

An extract of the major code function is shown below:

Hashtable options = JavaCore.getJavaCore().getOptions();
if(debugInfo!=null)
{
   if(debugInfo.equalsIgnoreCase("true"))
   { 
      options.put("org.eclipse.jdt.core.compiler.debug.localVariable",
         "generate");
      options.put("org.eclipse.jdt.core.compiler.debug.lineNumber",
         "generate");
      options.put("org.eclipse.jdt.core.compiler.debug.sourceFile",
         "generate");
   }else if (debugInfo.equalsIgnoreCase("false"))
   { 
      options.put("org.eclipse.jdt.core.compiler.debug.localVariable",
         "do not generate");
      options.put("org.eclipse.jdt.core.compiler.debug.lineNumber",
         "do not generate");
      options.put("org.eclipse.jdt.core.compiler.debug.sourceFile",
         "do not generate");
   }
}
JavaCore.setOptions(options);

Of course, the plugin.xml contained in the Application Developer directory plugins\com.ibm.ant.extras must contain:

<extension
   point="org.eclipse.ant.core.antTasks" >
   <antTask
      name="setDebugInfo"
      class="com.ibm.ant.extras.SetDebugInfo">
   </antTask>
      ... other stuff ...

The plugin.xml file and setDebugInfo Ant task are included in the download file com.ibm.ant.extras.zip that accompanies the Ant article referenced above.


Summary

Application Developer 4.0.3 compiles with debug information and there is no way to compile in non-debug mode. This article provided a GUI to change the compilation mode dynamically (for the current session, not permanently). This article also described a setDebugInfo Ant task (now included in the code download for the article Using Ant with WebSphere Studio Application Developer) that you can use to change the debug compilation mode during production Ant builds (which run Application Developer "headless").

Top of page



Download

NameSizeDownload method
sample.javacDebugOnOff.zip13.0 KBFTP|HTTP

Information about download methods


About the authors

Photo: Barry Searle

Barry Searle is the Migration Team Leader for WebSphere Studio Application Developer. He is a professional engineer who has worked at the IBM Toronto Lab for over ten years on various application development tools. Prior to that he had many years of industry experience developing command and control systems and leading complex communications development projects. You can reach Barry at searle@ca.ibm.com.

Photo: Barry Searle

Ellen McKay is an Information Developer for IBM Toronto Lab. She writes online help and publications for WebSphere Studio Application Developer. You can reach Ellen at ecmckay@ca.ibm.com.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=13205
ArticleTitle=Non-Debug compilations in WebSphere Studio Application Developer
publish-date=06012002
author1-email=
author1-email-cc=
author2-email=
author2-email-cc=