4

When I create a new project in Netbeans, it generates a build.xml file which it will use to compile and run the project, along with other stuff in folder nbproject.

Now, I want to have my very own build.xml file that I will use to compile to project on the server side. Some guys have tried to use the generated build file both in Netbeans and with pure Ant, but it's more trouble than it's worth.

I want to rename the auto-generated file to nb-build.xml and have my own build.xml file that Netbeans will not touch.

How do I achieve that ?

Community
  • 1
  • 1
Leonel
  • 28,541
  • 26
  • 76
  • 103

5 Answers5

11

Go into the nbproject directory in your project directory, and edit the file project.properties. Look for the section that looks like this:

# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results

and add the line:

buildfile=nb-build.xml

When you next open the project in NetBeans, it will create a new file of this name, and start ignoring the existing build.xml file.

Karl von L
  • 1,591
  • 3
  • 15
  • 22
3

We solved this problem this way. Assume your own Ant build script is called "myBuild.xml" and is placed in the same folder as build.xml - Open your build.xml file and replace its contents to:

<?xml version="1.0" encoding="UTF-8"?>
<project name="payroll_web_ice_jq" default="default" basedir=".">    
    <condition property="import.path" value="myBuild.xml">
        <not><isset property="netbeans.user"/></not>
    </condition>
    <condition property="import.path" value="nbproject/build-impl.xml">
        <isset property="netbeans.user"/>
    </condition>

    <!-- conditional import. If triggered from NetBeans, use old build script
                if triggered from shell, user new build script -->
    <import file="${import.path}" />

</project>

As you can see, we check for the existence of the "netbeans.user" property that only should exist within Netbeans and not on the command line. This works for us.

PÄlOliver
  • 2,502
  • 1
  • 23
  • 27
1

You can select the option Java project with existing sources or Web project with existing sources when creating your project. This will respect any existing build.xml file and create a secondary build file, I believe.

There is also an option when creating a project to use an existing build script, however I believe that this option will not generate a Netbeans build script for you, instead it will rely solely on the existing build script for all builds.

James McMahon
  • 48,506
  • 64
  • 207
  • 283
0

Try removing the import statement in the build.xml for the NetBeans generated build-impl.xml (i.e. <import file="nbproject/build-impl.xml"/>)and replacing it with an import of your nb-build.xml (e.g. <import file="nb-build.xml"/> )

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
0

Works like a charm: http://java.sun.com/developer/technicalArticles/java_warehouse/single_jar/

Tyler
  • 21
  • 1
  • 3