Re: how to programmatically add jar resource to Java project?

Cliff Draper <[email protected]> Mon, 27 Oct 2003 16:19:13 -0800 (PST)
Newsgroups gmane.comp.java.netbeans.modules.projects.devel
Message-ID <[email protected]>
From: "Timothy N. Jones" <[email protected]>
Date: Mon, 27 Oct 2003 15:16:02 -0800
> Through what magic incantation of API calls can I add a jar file to a 
> Java project as a resource?

This works for me.

First, get a basic ClassPath.  If you've got a ProjectMember, then you
can do that by ProjectPath.getBasicPath(ProjectMember).

            FileObject[] fos = FileUtil.fromFile(new File(jarFile));
            for (int fosNum = 0; fosNum < fos.length; ++fosNum) {
                PathResource pathR = ProjectPath.createResource(fos[fosNum], project);
                cp.add(pathR);
            }

Cliff Draper    Sun Microsystems, Forte Tools
My opinions may or may not reflect those of my employer.
---------------------------- food for thought ---------------------------
"He who lives by fighting with an enemy has an interest in the
preservation of the enemy's life." - Friedrich Wilhelm Nietzsche