Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Automatically edit project configuration in Nokia IDE at build-time

From Wiki
Jump to: navigation, search

This article shows how to create and run a (C#) program at build time to control your Nokia IDE project configuration.

Article Metadata
Tested with
Devices(s): Nokia Asha 310
Created: spiretos (31 Aug 2013)
Last edited: spiretos (17 Sep 2013)



The Nokia IDE is based on Eclipse, which among other things means that we can create and set programs to be run as part of the build process. This gives us the opportunity to automatically alter configuration files that we couldn't touch through our code.

This article shows how we can use this feature to automatically set an appropriate icon in our JAD file for the platform guidelines of the current target. We will first create the program that does this job and then set it to handle required changes right when our project is building.

The program

Then configuration file that contains the descriptions of our projects targeting platforms is the .mtj. This also contains the platform that we are currently targeting marked as active.

We use LINQ to query this XML file and find the active configuration. Then we store the platform’s name in our platform string variable. After we get the name we call the SetIcon function to make the desired changed in our application’s .jad file.

SetIcon searches for the line in the JAD file that contains the information about the MIDlets icon and changes it to that of the passed string iconPath argument.

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Xml.Linq;
namespace NokiaPlatformScript
class Program
static void Main(string[] args)
XElement root = XElement.Load(".mtj");
IEnumerable<XElement> activeConfigs =
from config in root.Descendants("configuration")
where (string)config.Attribute("active") == "true"
select config;
if (activeConfigs.Count() == 1)
string platform=((XElement)activeConfigs.ElementAt(0)).Attribute("name").Value;
switch (platform)
case "Nokia SDK 1.0 for Java": //Touch&Type
case "Nokia SDK 2.0 for Java": //Full Touch
case "Nokia_Asha_SDK_1_0": //New Asha
public static void SetIcon(string iconPath)
string newFileContents = "";
using (StreamReader sr = new StreamReader("Application Descriptor"))
string prefix = "MIDlet-1: ";
string[] midletTokens = null;
string line = sr.ReadLine();
while (line != null)
if (line.StartsWith(prefix))
line = line.Substring(prefix.Length);
midletTokens = line.Split(',');
newFileContents += prefix + String.Format("{0},{1},{2}", midletTokens[0], iconPath, midletTokens[2]);
newFileContents += line;
newFileContents += "\n";
line = sr.ReadLine();
using (StreamWriter sw = new StreamWriter("Application Descriptor",false))

Running the program at build time


  • Right click your project in Eclipse, click “Properties” and select “Builders”.
  • Click “New…” and select “Program”.
  • Give the builder a name. On the “Location” field set the .exe we previously created. Now set your project’s home directory as the “Working Directory”. Click OK.

That’s it! Now every time we build our project, the program we created will be called to make the required changes for us.

Related sources

This article is a complement for the Creating applications for multiple Nokia Java ME platforms article.

This page was last modified on 17 September 2013, at 16:08.
63 page views in the last 30 days.