[nbusers] How to write a Java program to simulate Netbeans open-project functionnality

  • From: Olivier Bourdon < >
  • To:
  • Subject: [nbusers] How to write a Java program to simulate Netbeans open-project functionnality
  • Date: Tue, 28 Aug 2012 16:49:49 +0200

The basic issue I am trying to address here is that I have a SVN repository which contains netbeans basic ant projects (as opposed to maven)
for which I'd like to implement a continuous integration chain. However the SVN does not include the build-impl.xml files as several target
platforms can be used to generate the "binaries" for these projects. Therefore I'd like to regenerate the missing netbeans configuration files
by "simulating" the Netbeans IDE open function for each project.

Having Googled this, I found several hints but none seems satisfactory as I do not know what to put as the .xsl files

I noticed that some of these .xsl file where included in the .jar of the netbeans platform like:
However I am now facing 2 issues:

a) how to assign my variables to use these files ? Guessing that this has to to with ClassLoader and getResource call but have no experience with this

b) I am also guessing that there is a upper level procedure which "guesses" what type of project I am opening (J2SE, J2EE, WEBservice, ...) as we can find other files like
therefore I am assuming that what I really need is to get access to this procedure but could not really determine where to look (I ran
egrep 'GeneratedFilesHelper|refreshBuildScript' on the Netbeans source tree but got lost in all matches)

The code I have currently copied and trying to get to work is:

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package netbeansrebuild;

import java.beans.PropertyVetoException;
import java.io.File;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Location;
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
import org.openide.filesystems.*;

 * @author olivier
public class NetbeansRebuild extends Task {

     * @param args the command line arguments
    public static void main(String[] args) {
        new NetbeansRebuild().xxx(args[0]);

    public void xxx(String dir) {
        // TODO code application logic here
        try {
            File projectDir = new File(dir);
            File buildXsl = new File("");
            File buildImplXsl = new File("");
            // Might be running inside IDE, in which case already have a 
            FileObject projectFO = FileUtil.toFileObject(projectDir);
            if (projectFO == null) {
                // Probably not running inside IDE, so mount it.
                // XXX for some reason including masterfs.jar in <taskdef> 
does not work. Why?
                // Possibly a bug in AntClassLoader.getResources(String)?
                LocalFileSystem lfs = new LocalFileSystem();
                projectFO = lfs.getRoot();
                assert projectFO != null;
            GeneratedFilesHelper h = new GeneratedFilesHelper(projectFO);
            if (h.refreshBuildScript(GeneratedFilesHelper.BUILD_XML_PATH, 
buildXsl.toURI().toURL(), true)) {
                log("Regenerating " + new File(projectDir, 
buildImplXsl.toURI().toURL(), true)) {
                log("Regenerating " + new File(projectDir, 
        } catch (IOException e) {
            throw new BuildException(e, getLocation());
        } catch (PropertyVetoException e) {
            throw new BuildException(e, getLocation());

Thanks for your time and help

[nbusers] How to write a Java program to simulate Netbeans open-project functionnality

Olivier Bourdon 08/28/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 25 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20150226.965aeb8). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
Please Confirm