Christopher Bottoms
Christopher Bottoms

Reputation: 11158

Given that NetBeans is installed, how can I use ant from the command-line (on Windows)?

I have NetBeans 8.0.2 installed on my Windows 7 (64-bit) machine. I have also the JDK installed (Java SE Development Kit 8 update 66 (64-bit)).

I want to run ant from the command line, but the closest I think I've come to getting it to run is the following:

java -jar "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar"

but I got the error

Error: Could not find or load main class org.apache.tools.ant.Main

I also tried the following, thinking that Main.class might be inside ant.jar, but got the same error:

java -cp "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar" -jar "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar"

I've spent at least an hour searching online and StackOverflow for the anser. The closest I've found is Compile NetBeans project from command line by using Ant, but it assumes that ant is accessible from the command line already.

Upvotes: 1

Views: 1659

Answers (1)

Christopher Bottoms
Christopher Bottoms

Reputation: 11158

To set up ant to work from the command line

  1. Add C:\Program Files\NetBeans 8.0.2\extide\ant\bin to your PATH
  2. Add the environment variable JAVA_HOME with the value C:\Program Files\Java\jdk1.8.0_66 (adjust this if you end up using a different version, of course).

Now that it is set up, simply use ant from the command line normally.

To rebuild the project, for example, simply do the following:

  1. Open a new command prompt
  2. Go to the project directory
  3. Type ant clean jar

Upvotes: 2

Related Questions