[TIP] Generate Values to JAD During Build Process

Sometimes you need to modify the build process of your project. There is build.xml file in your project directory that drives the build process. To open it in NetBeans, you have to switch to Files view (at least in Mobility project type). When you open it in the editor you might be surprised that there is only an import of build-impl.xml file and a comment in this file. Yes, the main build targets are defined in build-impl.xml file but you should never modify it because it's a generated file. If you want to add a build target or modify/overwrite an existing one you should do it in the build.xml

You don't have to overwrite the existing targets. There are defined following empty targets that you can define in your build.xml. And they will be run in the right time in your build process.

Defined pre/post targets:
  • pre-init: called before initialization of project properties
  • post-init: called after initialization of project properties
  • pre-preprocess: called before text preprocessing of sources
  • post-preprocess: called after text preprocessing of sources
  • pre-compile: called before source compilation
  • post-compile: called after source compilation
  • pre-obfuscate: called before obfuscation
  • post-obfuscate: called after obfuscation
  • pre-preverify: called before preverification
  • post-preverify: called after preverification
  • pre-jar: called before jar building
  • post-jar: called after jar building
  • pre-clean: called before cleaning build products
  • post-clean: called after cleaning build products



Generate Values to JAD during build process
You need to know what target you want to override, of course. I found out from the build-impl.xml file that the jad is created as part of the jar target. Therefore I will define the post-jar in my build.xml.

Modified build.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->>
<project name="" default="jar" basedir=".">
    <description>Builds, tests, and runs the project .</description>
    <import file="nbproject/build-impl.xml"/>
    
    
    <target name="post-jar">
        <!-- add all properties that you want to the JAD file -->
        <nb-output file="${dist.dir}/${dist.jad}" encoding="UTF-8" append="true">Lukas_property_1: Blablabla
</nb-output>
        <nb-output file="${dist.dir}/${dist.jad}" encoding="UTF-8" append="true">Lukas_property_2: ${name}
</nb-output>
    </target>

</project>
Please note that the not-intended </nb-output>. It's by purpose. The nb-output task copies the text as it is to the file.

The jad file will look like :
MIDlet-1: VisualMidlet, , VisualMidlet
MIDlet-Jar-Size: 62157
MIDlet-Jar-URL: MobileApplicationSVG.jar
MIDlet-Name: MobileApplicationSVG
MIDlet-Vendor: Vendor
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.1
MicroEdition-Profile: MIDP-2.1
Lukas_property_1: Blablabla
Lukas_property_2: MobileApplicationSVG 


Links:
Comments:

I had tried to modify build.xml earlier a couple of times but never git it right. Will try to open it and do it the way you are recommending. Thanks.

Posted by Studio Equipment on July 31, 2007 at 06:29 AM CEST #

@Studio Equipment: Feel free to ask a more specific questions here ;)

Posted by Lukas on July 31, 2007 at 07:22 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This is the main channel to share news, tips and other stuff related to my work. Sometimes you can find even personal stuff. Enjoy your reading...

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
news
Blogroll

No bookmarks in folder

OldNews
MyTrash
NavBar
NetBeans
LinksToBeExpanded