OscarRyz
OscarRyz

Reputation: 199215

Run NetBeans project just with ant

I have a sample code that was built with Netbeans.

It has a build.xml file so I downloaded ant and try to run it.

I've got this error message:

...... nbproject\build-impl.xml:76: Platform is not correctly set up

For what I can see, this is fixed by "simply" downloading Netbeans and running the sample from there, but... I don't want to install it to run a 10 files sample.

Is there a workaround to run Netbeans projects with Java? What's the correct .properties file I have to modify?

Upvotes: 20

Views: 22555

Answers (7)

Snicolas
Snicolas

Reputation: 38168

I just faced the same problem. I hope I could get rid of netbeans to go to eclipse and maven, just for that.

But here is a good link to export a ant built project from netbeans into a continuous integration server (or could be into any other IDE too).

Technique is going pretty well. Here is a summary:

  1. install netbeans on the CI server (there is an option to do it without gui, use -silent on the netbeans installer)
  2. include nbproject in SVN
  3. add to ignore list the private folder
  4. create your own private folder on CI server
  5. make it point to a folder of your CI server (mimicking a private user folder in the account used for CI)
  6. copy a real folder from a user to this folder and change every path (replace strings) to point to your netbeans install on your CI server.

And it should work.

Upvotes: 1

Mads Hansen
Mads Hansen

Reputation: 66714

It is possible to run the NetBeans generated projects straight from Java/ANT, but you may need to manually set some of the properties and/or add paths to jar files.

Unfortunately, NetBeans tends to include taskdef's using their own JAR files and reference properties that are defined only in the /nbproject/private/private.properties files, which usually get set when you first open the NetBeans project or modified as you edit the project in the IDE.

If you inspect the build-impl.xml you should be able to find the property and derive what value needs to be set(OS platform), then either:

  • create/set the property in the /nbproject/private.properties
  • add that property definition in the parent build.xml
  • pass in the commandline when invoking your ant target using -DPlatform=Foo

Personally, I like the structure of the NetBeans generated ANT files and targets, but hate how much custom/proprietary stuff they jam in that makes it hard to run without NetBeans.

For example:

ant -Dplatforms.JDK_1.7.home=/opt/jdk 

Upvotes: 12

albfan
albfan

Reputation: 12940

You can use this repo just for that https://github.com/albfan/ant-netbeans

It overcomes all the oddities of netbeans wrapped ant config so you just need:

To compile:

$ ant.sh compile

To run:

$ ant.sh run

To whatever (autocompletion):

$ ant.sh <tab><tab>

Upvotes: -1

Steve Ferguson
Steve Ferguson

Reputation: 802

I just went through this exercise with my NetBeans 7.0 project. What I was able to do was copy my build.properties file from my .netbeans\7.0 directory on my Windows system and make a server.properties file for my build server. This isn't much of a stretch, since every developer's build.properties may vary, so having another file for the server is to be expected. I then put together a simple server-build.xml file that references this file and does only the basics of init, compile, dist, and clean. I committed these two files to my CVS repository at the top level of my project directory, since they don't conflict with other project files and serve as a reminder in case something needs to be updated. Now I can build my project on my CI server with "ant -f server-build.xml" and everything just works.

My whole init section looks like this, giving my server paths priority, but including the necessary information from the NetBeans project properties.

<target name="init">
    <property file="server.properties"/>
    <property file="nbproject/project.properties"/>
</target>

I also had to do something similar when defining the ant tasks for my nested projects:

<target name="compile">
    <ant antfile="${project.MyProj-common}/build.xml" inheritall="false" target="jar">
        <property location="${build.dir}" name="dist.ear.dir"/>
        <property file="server.properties"/>
        <property file="${project.MyProj-common}/nbproject/project.properties"/>
    </ant>
    ...
</target>

I had to copy the j2ee.platform.classpath from project.properties to my server.properties file to ensure the references to j2ee.server.home resolved as I needed. I didn't expect to have to do this, but the classpath was wrong otherwise, causing the build to fail.

Thanks for the information on this question, as it helped guide me to this solution.

Upvotes: 1

leif.gruenwoldt
leif.gruenwoldt

Reputation: 13957

I'm using Netbeans 6.8 and java projects that were created with Netbeans can be run from the Netbeans auto generated build files with just ant on the cli. All the regular targets like ant compile,ant run,ant clean, etc "just work". (I'm using Fedora 13 if that matters)

Upvotes: 0

Slartibartfast
Slartibartfast

Reputation: 8805

I've just successfully built NetBeans project with ant. These were the things I had to do:

  • Copy <NetBeans-folder>/java2/ant to a "Netbeanless" machine
  • Copy nbproject/project.properties to, say, ant.properties
  • Replace every ${} expression in ant.properties with it's value
  • Add platform.<platform-name>.home=<path to platform>
  • Add libs.CopyLibs.classpath=<path to nb-ant>/extra/org-netbeans-modules-java-j2seproject-copylibtask.jar
  • Add other needed classpaths into javac.classpath (e.g. path to servlet-api.jar)
  • ant -propertyfile ant.properties

It works, but doesn't make me happy. I would either like to find the way to reuse project.properties, or to automatically translate it to a "resolved" version (step 3). Build could then be automated.

Upvotes: 4

James Schek
James Schek

Reputation: 17960

Just to add to Mads' answer... usually, you need to install and open Netbeans at least once on the target machine. The ANT projects also rely on a few settings from the USERDIR/.netbeans/... directory. This may have changed with 6.5+.

This will get some of the base settings configured and define the classpath's to netbeans jars. If your dependencies (i.e. libraries) or project is being run from a different directory since the last time you opened the project in Netbeans, you will need to tweak a few settings in the private.properties file as Mads' described.

Upvotes: 0

Related Questions