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:
-
Switch to the desired perspective.
-
Select Perspective => Customize. Expand Other and select JavacDebugOnOff. Click OK.
-
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.
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").
| Name | Size | Download method |
|---|---|---|
| sample.javacDebugOnOff.zip | 13.0 KB | FTP |
Information about download methods

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 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.



