Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run NetBeans project just with ant

Tags:

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?

like image 995
OscarRyz Avatar asked May 26 '09 20:05

OscarRyz


2 Answers

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 
like image 78
Mads Hansen Avatar answered Oct 31 '22 20:10

Mads Hansen


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.

like image 41
Slartibartfast Avatar answered Oct 31 '22 22:10

Slartibartfast