« srpen 2005 »
PoÚtStČtSoNe
1
2
3
4
5
14
    
       
Today

Navigation

Speaker Profile
Roumen's Weblog
Login
Sun Bloggers
Technorati Profile

Am I popular?

Today's Page Hits: 476

Contacts

Name: Roman Strobl
E-mail: roman dot strobl
at sun dot com

NetBeans

Java Sites

Javalobby
The Server Side
Java Tips
Java Blogs
java.net
java.sun.com
java.cz

Blogs

NetBeans:
Geertjan
Brian Leonard
Gregg Sporar
Lukas Hasik
Ludovic Champenois
Vincent Brabant
Alexis Moussine-Pouchkine
Jullion-Ceccarelli
Tom Ball
Tim Boudreau
Jesse Glick
Petr Blaha
Ruth Kusterer
Jara Uhrik
xzajo
Jan Lahoda
James Branam
nbextras.org

Sun:
Kazem - bug cartoons ;-)
Tor Norbye
Romain Guy
James Gosling
Chief Gaming Officer
Bill Vass
Jim Grisanzio
Jonathan Schwartz

Planets:
Planet Netbeans
Planet Sun
Planet Eclipse

Other:
netbeans-blog.org
Joel Spolsky
Bruce Eckel

License info

Creative Commons License
This work is licensed under a Creative Commons License.

Recent Entries

Map of visits

Locations of visitors to this page
« Previous day (Aug 11, 2005) | Main | Next day (Aug 12, 2005) »
20050812 Pátek srpen 12, 2005
Hacking NetBeans #3 - Registering Files in Default Filesystem

Last time I blogged about executing ant tasks from the IDE. It was done in an ugly way - by generating a temporary ant script for execution. A nicer way is to use an existing ant script, which will be placed somewhere in the module's jar.

But the question is: how to access a xml file which is located somewhere inside my module? Or any other arbitrary file?

Well, you need to register this file in NetBeans layered filesystem. To achieve this, add something like this to the layer.xml file:

    <folder name="Services">
        <folder name="MyModule">
            <file name="my_script.xml" url="resources/copy_script.xml"/>                
        </folder>
    </folder>

By this I am declaring, that the export_script.xml file is located in resources/export_script.xml inside my module. This path is relative to the path of the layer.xml files. So these files are:

org/netbeans/modules/mymodule/layer.xml
org/netbeans/modules/mymodule/resources/copy_script.xml


I also declare that my module can find the xml file in Services/MyModule/copy_script.xml on the default NetBeans filesystem. To access the file, I use:

        FileObject sfo = Repository.getDefault().getDefaultFileSystem().findResource("Services/MyModule/my_script.xml");

Now that I have a reference to the FileObject of the xml file I can do something useful with it. I can e.g. convert it to a regular file by using FileUtil.toFile(sfo). To execute the ant script you can use my previous example but you will need to copy the ant script to the disk at first and call RunTarget() method on a FileObject which resides on disk.

Confused about NetBeans filesystems and the layer.xml file? I was, too. A good and short reading is here from Tim. You can also use the sysfs plug-in to explore the default filesystem. It's full of surprises :-)


    Disclaimer: The contents of my blog represent my personal opinions which may differ from official views of my employer, Sun Microsystems.