Hacking NetBeans #5 - Boundling a Library with Your Module



Unless you're doing something very standard there is a probability you'll need to include an additional library with your module. At first it's a good idea to take a look if the library is not included with the IDE (in module/ext subdirs of individual clusters). In that case you can just declare dependence on the module which boundles the library and you're done.

However you probably won't be so lucky and you'll need to provide the library yourself. As I was told it's better to provide your library as a single module - this way others can then depend on this module if they need the library. Some useful info about this is here. There is a new wizard in NetBeans Plug-in Modules | Library Wrapper Module Project which can do most of the job for you if you want to create a library wrapper module.

The other possibility is to add the library directly into your module which has an advantage that you provide single a nbm with everything. Create a subdirectory e.g. external and place the jar into it. It's a good idea to change the name of the jar, e.g. from mail.jar into mail-1.3.2.jar so that other people can find out what's its version easily.

In order to get the jar copied into your nbm, you need to add something like this to your build.xml:

    <target name="netbeans-extra" depends="init">
        <mkdir dir="${cluster}/modules/ext"/>
        <copy todir="${cluster}/modules/ext">
            <fileset dir="external">
                <include name="mail-1.3.2.jar"/>
            </fileset>
        </copy>        
    </target>

This way you create a modules/ext subdir in your nbm and copy necessary libraries into it. You may need to get the library on classpath, so that it's visible for other modules. The classpath extensions are specified in project.xml like this:

            <class-path-extension>
                <runtime-relative-path>ext/mail-1.3.2.jar</runtime-relative-path>
                <binary-origin>external/mail-1.3.2.jar</binary-origin>
            </class-path-extension>

To add more jars to classpath just use additional class-path-extension tags. You get the same effect if you add the Class-Path: property into your manifest, but this method is deprecated - use project.xml for this purpose.

You will also need the IDE to recognize the jar, so that you can use code completion, methods called from the library don't get underlined as errors, etc. This is done by adding a property into the project.properties file:

cp.extra=\\
    external/library1.jar:\\
    external/library2.jar

Similar properties are used for tests - test.unit.cp.extra and test.qa-functional.cp.extra, so if the IDE doesn't recognize the API provided by the library, you're probably missing them.

Note that there are special requirements on libraries hosted on www.netbeans.org, this document explains what needs to be done. The document explains everything necessary about scrambling and unscrambling, how to add a license to the nbm and few other legal topics (legal stuff is boring but you need to be correct).

I've been fighting quite a lot with adding a library to ant's classpath, this is a larger topic so it will deserve another post. Btw, if there's any area about module development you find fuzzy or underdocumented, let me know, I like finding out how things work. I can't guarantee that I will understand everything perfectly, but just writing about how things work for me might help other people out.
Comments:

Trung Duc Tran assures me that scrambling is going away: http://weblogs.java.net/blog/richunger/archive/2005/07/i_prefer_my_jar.html

It should be noted that the reason library modules are recommended over this method is so that the library can be shared among multiple client modules (analogous to the difference between static compilation and dynamic linking).

Posted by Rich Unger on srpen 22, 2005 at 12:54 odp. CEST #

Yes, there's work being done on getting the scrambling removed... hopefully we'll get rid of the pop-up show. I was very much surprised when I saw the licenses when I did my first build of NetBeans.

Posted by Roumen on srpen 22, 2005 at 02:08 odp. CEST #

Today 12:50:17 Hi, In my wrapper module's project.xml i find the following xml code : < class-path-extension > < runtime-relative-path >ext/junit-3.8.1.jar< /runtime-relative-path > < binary-origin >release/modules/ext/junit-3.8.1.jar< /binary-origin > < /class-path-extension > Is it possible to locate my jar from another place on my disk? I need this so my wrapper automatically takes the last version when the jar is updated by maven.

Posted by Griet Préal on listopad 14, 2005 at 05:23 dop. CET #

I went through this whole procedure and everything worked except that the external jar is not getting included in the .nbm. The external jar does show up under build/cluster/modules/ext. Please help. Thanks

Posted by Darren on únor 03, 2006 at 12:36 odp. CET #

Please ask on dev@openide.netbeans.org - I do not know if anything changed since I was experimenting with this.

Posted by Roumen on únor 03, 2006 at 03:17 odp. CET #

In order to get the external jars included in the .nbm file, also add the following entry in the project.properties (tested with Netbeans 5.0):
extra.module.files=\\
modules/ext/library1.jar,\\
modules/ext/library2.jar

Posted by Andrea on srpen 02, 2006 at 02:43 odp. CEST #

Post a Comment:
Comments are closed for this entry.
About

Roman Strobl

Search

Archives
« duben 2014
PoÚtStČtSoNe
 
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