index

The Taming of the Ants: Customizing NetBeans4.0!

The new version of NetBeans, 4.0 is based on a terrific system that every project would work under the Ant Scripts. It seems all the force of the developing team should be focused on that and as a result, many facilities used to equipped in good old version 3.6 was blown away ! But, you could edit these Ant Scripts or other configuration files to customize every project as fully as you like!? So go try if I could get those lost facilities of NB3.6 back to NB4 again!...

Note that NB4 is Daily Build at October 26, 2004. The Beta2 is so BUGGY.

Mission 3:Developping Zaurus App /Emit classes into Zaurus' memory/Script for let the app run/Output error message into a file/A mystery of the compiler's version/A great encouragement /Noniko the code-hacking novice /Answer from a true code hacker/

Mission 2:Mounting Filesystems /Well, it's a pushover

Mission 1:Execution directly from a jar archive /What I want to do/ Where to put a jar file without sources/ Run the "Main.class" file! /The mighty free-formed project/Edit the configuration files/Run the "NewMain.class" fileI/Customized menu item


Mission 3:Developping Zaurus App


EMIT CLASSES INTO ZAURUS' MEMORY

Through the Mission2 I knew in the projects of NB4 not only source files' directory but also class files' directory could be located anywhere. This means NB4 could be used to development of Zaurus apps as well as NB3.6.

Using NB3.6, you could mount remote samba-shared directories of Zaurus' memory to create or edit files directly there. Using NB4, the same thing could be done by creating " a project with existing source file", setting "the folder containing the source" to be one in remote Zaurus' memory, and after creating the project editting project.properties file to set directories for build products to be also ones in Zaurus' memory. The details are as below...

My Zaurus SL-C760 could be connected within my home LAN via wireless CF card. An companion software "terminal" is installed in it.
As for providing samba-shared directory in Zaurus, click here.

Now let's return to NB4. Create "a java project from existing source", setting the source-containing folder to be one in samba-shared folder of Zaurus. In the picture below, drive Z is assigned to the shared root of Zaurus.

Meanwhile, the project forder is set to one in PC. Therefore the project "zproj0" was created. The first thing to do is to open the private.properties file to find the value of the folder containing source packages.

This is it! Copy the string "Z:\\nonijava\\ztest0\\". Then open the project.properties file. This time the value of ${build.dir} should be edited, because I desided to deposit other build products to Zaurus' memory, for example, script files.
By default, ${build.dir} =build. This is a relative path and means actually ${build.dir} = c:\nonidata\nb4works\zproj0\build. So paste the string copied before the string "build".

Then look at the value of ${build.classes.dir}. It is left untouched, meaning the value to be Z:\\nonijava\\ztest0\\build\\classes.

Now let's create under the project zproj0 a package Z0 and a source file NewMain.java.

Edit it to be a simple program, and build the project. Take a look at output at building the project.

As you can see above the industrious ant makes a directory "build" and so on in Zaurus' memory. It also makes a jar file as shown in the output, but now we will not use it.

Unfortunately this build directory is not displayed either Projects nor Files windows of NB4. The only way is to use OS' file browser

:

There! opening this build directory, you could see the NewMain.class file in the classes subdirectory.

SCRIPT FOR LET THE APP RUN

Now we have a class file so let's write a script file to run it. Where shall we locate this script? Right under Source Package node of Project window!
To create a file, invoke New File Wizard by selecting "File"->"New File" from Menu bar. Choose "Other"->"Empty file" as File Type.

It's an improvement with NB4...NB3.6 allowed only to create text file other than those listed. Oh it might be the first time I felt a better feature of NB4 compared to NB3.6 at a glance. Since now there were so many dramas such that I got a bad shock at first by its change and after struggling for some time discover at last the hidden advantage of it. Anyway, the script file is named runnewmain.sh.

Here is the content of the script.

#!/bin/bash
PATH=/home/QtPalmtop/j2me/bin:$PATH
export PATH
cvm z0.NewMain -Djava.class.path=.

Above, cvm is the running command of Personal Profile.

After preparing the script, build the project. Take a look at the output message.

You see? Create a file under the Source Packages node and build the project, so the file goes copied to the classes folder.

Now it's time to work on Zaurus. Push the keys of its tiny keyboard with two fingers. While the default home directory is /home/zaurus, go down to the directories where the script file is located.

$cd zsamba/nonijava/zproj0/build/classes

Make the script file executable.

$chmod +x runnewmain.sh

Then let it run!

$sh runnewmain.sh

.....Error messages were printstacktraced one after another after another after another....

OUTPUT ERROR MESSAGE INTO A FILE

I CONFESS I'M DEADLY POOR AT SHELL OPERATION.

Study of UNIX shell is, for me, usually boring and something could be replaced with GUI,and when I get forced to use it I'm too panic to research how to use it. This bad attitude is often blamed by my hubby saying "So your UNIX carreer is just a heap of garvage". This time I was worried that the error message was too long for this tiny terminal window and the first part to show the exception type was gone scrolled away everytime when the output finished. What in the world exception is occurring? How shall I get the output step by step? ....The solution was to decrease font size.

Poorest idea.

Afterward I got a better one. How about writing output into a file? I digged the proper command out from my old memoranda:

$sh runnewmain.sh > &error.txt&

Then I got the whole error message. It was:

java.lang.UnsupportedClassVersionError: z0/NewMain (Unsupported major.minor version 48.0)
at sun.misc.Launcher$AppClassLoader.findContainer(Ljava/lang/String;)Lsun/misc/Launcher$ClassContainer;(Native Method)
at sun.misc.Launcher$AppClassLoader.access....

A MYSTERY OF THE COMPILER'S VERSION

I forgot to write that I use this NB4 with J2SE 1.4.2_04. Let's try it again using NB3.6 with the same J2SE in the same PC and for same source file.
Welcome back, good old NB3.6! Let me mount the directory Z:\nonijava\zproj0, to locate the source and the class separated from those used by NB4.Then copy the required files from NB4's project folder...

build and src folders are used in NB4's project.

Right-click NewMain.java, selected in the above screenshot, go compile. The class file was created where the source file is located.

Then return to Zaurus. Invoke the copied script and run this z0.NewMain.

WORKED!

With the same J2SE...What's the difference!?

A GREAT ENCOURAGEMENT

Now what shall I do? It's pretty like many miles beyond my ability. Is there anyone dealing with NetBeans and Zaurus at the same time?(Later I googled and found a few in some forums). Still more(less?) a trouble in NB4 dev version!? I know it's not a supported way to developing appications for Personal Profile, so it might be impossible for the reason of specification. I have many many other things to try with NB4 and it might be a waste of time to stack with it...

I wrote about my hesitation to NetBeans.ORG ML. "Shall I continue this challenge? Please show me the way, Brother"

Brother Tim gave me an answer that he is also interested in Zaurus and It should be the matter of compiler used in IDE and I should check javac.source property of the project.properties file because it might be 5.0, too new version to be supported by Zaurus.

Now I got the way! Go straight!....but javac.source was 1.4. More precisely, in project.properties file,

javac.source=${default.javac.source}

and this ${default.javac.source} is described in the build.properties file located in <home directory( That useless Documents and Settings...)>\.netbeans\dev directory. the value there was

default.javac.source=1.4

Umm, so it's obvious the compiler version is 1.4 also for NB4. So what's wrong? But I had made up my mind never to get back now knowing that there was a friend encouraging me.

NONIKO THE CODE-HACKING NOVICE

Then I happened to remember an article once I read in a magazine "JAVA Developer(Softbank Publishing Ltd.)". It was on Java byte codes, I could not understand it exactly but enjoyed a code-hacking flavor from it. I remembered in that article it was written such that Java class files are not complete binary-coded and each first line of them expresses the version number. Isn't it javap command to get information from class files? Open a command pronpt window and....what are options of javap command?...What about the class files located in a remote drive?....

I'D RATHER OPEN THEM.

I mean, open the class files in force by a text editor! I have a highest-performancing editor Peggy. I ope\ned, like opening cans with a can opener, the two NewMain.class files, compiled using NB4 and NB3.6. What I saw were, as expected, the contents like rare steaks, composed of readable words and unreadable characters. Anyway I watched them to compare.

OOOOps.

There was a difference, only one difference in the first line!

NewMain.class by NB4

NewMain.class by NB3.6

Sorry for the cursor at the head of the line in screenshot for NB4 case. The difference is the third charecter back from the end of the line! "0" for NB4 case, while "." for NB3.6 case!

.......

Yes, I did edit the NB4's class file, replacing "0" with "." Save the file and run the script for it.

WORKED!

It was an excitement. I made it sure for many times not to cry out in vain. I created a new NB4 project, added a new source file, compiled it, end edited the class file in the same way, and succeeded. Then I rushed to the keyboard to report this fact. After sending it I felt no one would understand my mail because I was so excited and might have write so terrible English...

ANSWER FROM A TRUE CODE HACKER

But there was an answer to the report I wrote in so confused English as a seal's screaming.The sender's name was Gunnar! I have known his name because he often gives many advices to many strayng NetBeansers.

He wrote me that the charecter "0 "means J2SE1.4 while "." means JDK1.2 so the actual compiler version for NB3.6 case is not what I expect to be.

OH MY BUDDHA! That's really code-hacking! You really a code hacker, Gunnar! You gave me a definitive, final, ultimate solution!...But it means it was NB3.6 that had used different version of compiler. Why, why my good old NB3.6? Is it your way to use as old version as possible?...Anyway, all right, only I have to do adapt this knowledge to how Tim had teached me to do.

I made another new project using remote directories of Zaurus and edited the project.properties file.

default.javac.source=1.2
default.javac.target=1.2 (Perhaps not bad to edit this too)

Building the project, returning to Zaurus and run the script...WORKED!!

Yeahhh! Thank you two, Tim and Gunnar! NetBeans.ORG ML really helps like heaven!


Mission 2:Mounting Filesystems


WELL, IT'S A PUSHOVER

In NetBeans 3.6, working directories set by "Mounting Filesystems", as follows: First, you make a new directory, for example, named thisprog, anywhere you like. Then, select "File"->"Mount Filesystem" from menu bar and set thisprog directory to mount. Therefore a new node "thisprog" appears in "Filesystems" window, so you can create any packages or classes under it. If you create a new class thispkg.ThisProg, All you will see in Filesystems Window is a ThisProg.java node.

FileSystems Window in Japanese.

After compiling this, let's browse this c:\nonidata\nb36folder\thisprog\thispkg directory by a file browser of your OS.

you will see the class file in the same directory.

I believed for a long time this "mounting" operation as one of the most clever, spicy, smart "philosophy" of NetBeans. It made any directories in local, even remote, machine available as workspaces, in one project. To leave off that workspace, select "unmount"...but can you imagine the shock I got when I first try NB4 and found no "Mount Filesystems" item in "File" menu? I thought it was still under development and waited for a month or so, expecting this good old facility to be added, but what I saw at last in netbeans.org webcite was the declaration such as "In NB4 there's no more mounting system. Now when you open "File" menu there are only items to create, open, or close a tiny project as Eclipse....

Following the wizard what you get is still Eclipse-like windows, "Project" like"Java Perspective", "Files" like "Resource Perspective" of Eclipse!

. "Project" window

"Files" window

I won't speak ill of Eclipse style itself. I want to say if I must use Eclipse-like system with buggy new-type NB4, why not use Eclipse itself from the beginning?...Write a source file, compile it, so you will get the class file in "build/classes" directory. Oh, good work, everything in order. Welcome, an ordinally peaceful harmless NB4...
That was my first impression.

BUT!...later I knew this mouting behavior could be produced also with NB4. No, a better behavior! "Project from Existing Source " is the start point to turn NB4 to exciting, enchanting, thrilling, epoch-making one!...

Let's introduce to NB4 ThisProg.java source written by NB3.6. In New Project Wizard, select "Java Project with Existing Source".

Next, select the folder containing the source. The folder should be the classpath to use that source. In this case it's easy, you could choose the folder to mount in the case NB3.6. As for project folder, you can locate it to a completely different place.

before completing the wizard, a dialog appears to confirm whether delete or ignore existing class files.

I think this message of NB4 is lack of respect for it's ancestor, because usually these class files should be legacies of 3.6. But nothing will proceed while murmuring. Go Noniko, select "Ignore".

Therefore a new project thisprogby4 was created. The display of Project window is:

After building the project the product is displayed in Files window:

:

The class file shown under "Source Packages" folder is the procducet of NB 3.6 "ignored". So you can use this source and class again with NB3.6. Products and cofiguration files specific to NB4 are put into thisprogby4 directory, without trespassing on the folder used by NB3.6. That's beautiful!

And if you long for former system to set source and class to the same directory, it's possible.
Let's open "nbproject " directory.

There are many property files and lots of properties to edit. Don't forget about "private.properties" hiding in private folder.Open it and look here!

The value of ${file.reference.nb36folder-thisprog} is that selected as the folder containing the source.Then open project.properties file. output destination of the class files is shown here as ${build.classes.dir}.

.

to locate classfile together with its source, edit as follows:

build.classes.dir=${file.reference.nbfolder-thisprog}

Let's assure the effect with a new project. prepare a new directory named mountit. Create "a java project with existing source". Set mountit folder to be the folder of containing source packages, the project name to be mountitproj and the project directory to be, for example, c:\nonidata\nb4works\mountitproj.
Edit the project.properties as descrived above. In this case,

build.classes.dir=${file.reference.nb4works-mountit}

Create a source file under the project mountitproj, then build the project.

Then you will see the class file together with its source. It's just as mounting mountit directory by NB3.6. It's more than that as specific files are not inserted in the "mounted" directory . You can again use any directories as workspace by editing the project.properties file!


Mission 1:Execution directly from a jar archive


WHAT I WANT TO DO

Using NB3.6, we could mount a jar archive as a filesystem and make operations to run main classed in it. Here I made a sample file "app12.jar" which contains two classes having main methods. Each main method is to print a simple message.

Now let's treat this by NB3.6. I'm going to describe simply because I feel very sad longing for it.

Select "File"->"Mount Filesystems" to start New Wizard.
Select "jar archive" as filesystem.
Browse the path of app12.jar and input it.

So you see a node for the mounted jar. Click it and expand the node-tree. You see two executable class file, Main.class and NewMain.class. Each you can excute only by right-click it and select"Execute"!!!

Sorry, the screenshots are for Japanese version...Enjoy the Far-East flavor...

Too easy to stop my tears! You might get it even by my poor English explanation.But NB4.0

LOST THIS FACILITY.

I even hate to decribe HOW I FAILED TO DO THIS WITH NB4. I must say you will know the fact at the moment you select "Files"... But it was very much convenient way to operate many open source tools with the IDE, like Axis, Castor, or Hibernate. So it is the first mission to find some other way to realize the above operation also with NB4.

WHERE TO PUT A JAR FILE WITHOUT SOURCES

The first question is where to put this app12.jar file. Projects of NB4 have turned to tiny ones like Eclipse, from big ones of NB3.6 to take any files or directories. " Sources are here, classes are there, set only one main class, Don't look other files in Projects window"... a nervous project system. Even if you create, for example, a "lib" folder by yourself, you cannot find it in "Projects " window. All existing files or directories are found in "Files"window.

<->

By the way, the good news on NB4 project is you can set files out of the project into its classpath. So you don't need introduce the jar arcive into any projects. So I created a directory at simpler filepath,"c:\nonidata\nb4works\nb4libs" to put and share all library files. How I access such an independent directory from NetBeans?...

This is the way. Select "Window"->"Favorites", so a new "Favorites" window appears cascated with "Projects" or "Files" windows. In this "Favorites" window at first you will find your home directory, or what Windows insists is it. Right-click the root "Favorites"and select "Add to Favorites..."

You can choose, for example, c:\nonidata\nb4works\nb4libs from a FileChooser window. At last a new "Favorite" is seen like below:

Next, how to introduce files from other directories: Now "app12.jar" is located right under "c:\nonidata". So I added the directory to the "Favorites" window.

Sorry too many subdirectories are scattered under "nonidata". Anyway, search "app12.jar" file under it, select the node, and you can make the familiar operation "copy and paste"within the "Favorite" windows. In this way "app12.jar" file was introduced into "nb4libs" directory.

RUN THE "Main.class" FILE!

First, try to run at least the "Main.class" file in the archive. I made a new project "gojar" for it. Select "File"->"New Project..." to start New Wizard...

AN ECLIPPIE-LIKE INTERFACE.

Good, good. Anyway, select "General"->"Java Application" and click "Next".

Set "gojar" for ProjectName.
Set Project Location and Project Folder.

Turn off the both checkboxes of "Set as Main Project" and "Create Main Class"...you can shout

No Thanks

when you turn them off. Anyway, an empty project "gojar" was created. Though there are many configuration files in "neproject" directory as you can see in "Files" window, let's leave them untouched

UNTIL LATER.

what I want to tell now is there are no source files in "src" directory.

<->

Set the project to refer app12.jar. Right-click "gojar" node in "Projects" window, select "Properties"...

Below is the Project Properties window. Click "Run"->"Running Project". Click "Add@JAR/Folder" beside the list "Classpath for Running Project".

Choose "c:\nonidata\nb4work\nb4libs\app12.jar" from FileChooser ande set it to add the list "Classpath for Running Project"...

Then input in "MainClass" field above. The IDE Help document says you have to input directly a fully qualified name. You cannot browse other than ones with source files within the project. If you are not sure about the name of the class to set, you can find it in "Favorites" window like below:

You can find the name "app1.Main"

Then input it.

Get ready! Let's go right-click the "gojar" project node and select "Run Project"...

FAILED

The IDE claims "No main class is set"or something like that...RTFAS(Read the ....Ant Script)!!!...But there is only one thing left to try.

THE MIGHTY FREE-FORMED PROGECT

It's the mighty Freeform Project! You can make fully customized project based on your own Ant script. I did not write my own script, instead, fed the "gojar"'s script to a new project !

Start "New Wizard" once more by "File"->"New Project...".This time the choice is "Java Project with Existing Ant Script". Click "Next".

Name and Location."Location" is the directory of required configuration files. This time the "nbproject"of "gojar" project is avaliable."Build Script" is the Ant script to use. Set as well the "build.xml" file of "gojar"project. Yes, the setting described above at last works here!

The new free-formed project name is "gogojar". The checkbox "Set as Main Project" is as you like. You can set it on or off anytime later.

Click "Next" and the window like below appears. It is for mapping an IDE menu item to Ant target. Now leave these even tha blank field, untouched.

Click "Next" again and you will see the window like below. Skip this as well. You can

say again "I am struggling with operating a jar WITHOUT SOURCE"

while just clicking "Finish".

In this way, a free-formed project was created as shown below.

Can't you see the ant drawn in the icon walking on two feet?
It has simpler logical structure than the first project "gojar".

The actual structure is very simple, too. Why is there no "build.xml" node in "Files" window? This is a good trick of "Project" window. The "build.xml" node seen in "Project" window is alias, or shortcut of the one in "gojar" project! You will find its file path by right-clicking it and selct "Properties". ( I don't now why this "build.xml" node is not shown under it's own project "gojar" in "Project" window...)

Double-click the "project.xml" node and search this part in the editor.

the above descirbes the "gogojar" project should use the setting of the "gojar"project as is.

Now, Run the project! Right-Click the ant-drawn "gogojar" node and select "Run Project"...

The output is...

DONE

Why by "gogojar" not by "gojar"? A bug? A spec?...anyway, we've done it! Though it took much longer and harder time than the case NB3.6....

EDIT THE CONFIGURATION FILES

@Being much relieved by success in running at least one main class, I investigated the configuration files in "nbproject" directory. The investigation was like one in a muddy pond, so the procedure is not shown in detail. Anyway it was found the main class of a project is set in the file "project.properties".

A part of the descripsion is shown below. Many key-value mapping is written in this property file. Look at the key "main.class".

It corresponds to the setting "Main class" in the Project Property window of "gojar" project.
I added another setting as shown below about the other main class "app2.NewMain"...

Next, open the file "build-impl.xml" of "gojar"project. It's very long because all the settings required to manage one application project are wrtten in this. The file "build.xml" only refers to this file. Of course, we must beware the fact if this build-impl.xml get damaged, the project itself is destroyed.

In "build-impl.xml", how to use java command is defined in the target here in this part..." -init-macrodef-java"!

This time we don't have to edit the above, but we must get the meaning of several important setting...

We could think this target like to give an extension of the original Ant task "java". So a special identification is given to this special java task:

uri="http://www.netbeans.org/ns/j2se-project/1"

At first I thoght there might be another file or something to define this namespace, but it seems this is defined in this file itself.
This special java task has an attribute "classname" as defined:

<attribute name="classname" default="${main.class}"/>

the variable ${main.class} means

main.class=app1.Main

written in "project.properties" file.

We could summarize that the above target would mean like:

This is the special java task identified by the name "http://www.netbeans.org/ns/j2se-project/1".
The special java task has an attribute "classname" to indicate the main class to run with the original "java" command.
If you don't specify the class name, the default value is used.
As for the actual file name, see the key in project.properties.

Keeping above in my mind, I edited the part below.

Watch at the target "run". the tagged description

<j2seproject:java xmlns:j2seproject="http://www.netbeans.org/ns/j2se-project/1">

calls "The special java" discussed above. We could think this tagged description would mean

The special java task is expressed here as "j2seproject:java"
where "j2seproject:"corresponds to "http://www.netbeans.org/ns/j2se-project/1"

Not exact, but simple expression. Isn't it?

Sorry I have not tried on the target "run-single" yet. Maybe next time. Here what I did was to insert a new target "run2" , in between the targets "run"and "run-single".

Yes, it's almost a copy of the target "run". The difference is in the description

<j2seproject:java...

I set below:

classname="${main2.class}"

which means the class "app2.NewMain"! Feel like I could do it!

RUN THE "NewMain.class" FILE!

Now go try this! At first( or you could finish by this if you are satisfied) let's test with running Ant target directly. Go to "File" window and expand the node-tree of "build.xml" file under "go jar"project . Expose all targets hanging on it.

The above picture shows only a few children in the upper part. To show all the targets I must take a very long screenshot. Scroll it down to find the two targets "run"and "run2".

Right-click "run2"and get it run!

Yeah! It worked! I also found app1.Main run if I only right-click the node "run"! I even began to feel no Free-formed project perhaps needed for this purpose !?! Anyway, let's use the special feature for it..That is...

CUSTOMIZED MENU ITEM

Go to "Project" window, Right-click "gogojar" and select "Properties". Click "Build and Run"in "Project Properties" window.

Leave the upper fields, including the blank one, untouched. Look at the last one titled "Custom Menu Items:".Click "Add" button on the right hand. a blank row with two columns appears. Click the blank colum of "Ant Target" and you will get the combo. Select "run2"from the listed targets.

Input for example "Run Main2" as "Label".

After filling this field you shuld confiem the input by pushing enter key, or the input would be erazed when you close the window.

Get back to "gogojar"project. Right-click the walking an icon in "Project" window ...

Hey! Do you see the menu item "Run Main2" in the context menu? Now select it! Did you get output from "app2.NewMenu"?...

Let me take a rest.

A tough work! Tough work to get the results used to get by one-right-click with NB 3.6....In return I got a lot of knowledge on NB4.0, that's good, but...

Is it really a task required for an end user like me?

or something like that was what I wanted to say finally, in one beautiful afternoon in october....

Oct 28, 2004

Back to top