简体   繁体   English

鉴于已安装NetBeans,如何从命令行(在Windows上)使用ant?

[英]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. 我在Windows 7(64位)计算机上安装了NetBeans 8.0.2。 I have also the JDK installed (Java SE Development Kit 8 update 66 (64-bit)). 我还安装了JDK(Java SE Development Kit 8更新66(64位))。

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: 我想从命令行运行ant ,但是我认为使它运行最接近的方法如下:

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: 我还尝试了以下操作,以为Main.class可能位于ant.jar ,但出现了相同的错误:

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. 我花了至少一个小时在网上搜索,并在StackOverflow上搜索了分析服务。 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. 我找到的最接近的是使用Ant从命令行编译NetBeans项目 ,但是它假定可以从命令行访问ant

To set up ant to work from the command line 要设置ant以从命令行工作

  1. Add C:\\Program Files\\NetBeans 8.0.2\\extide\\ant\\bin to your PATH C:\\Program Files\\NetBeans 8.0.2\\extide\\ant\\bin到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). 添加值为C:\\Program Files\\Java\\jdk1.8.0_66的环境变量JAVA_HOME (当然,如果最终使用其他版本,请进行调整)。

Now that it is set up, simply use ant from the command line normally. 现在已经设置好了,只需正常使用命令行中的ant即可。

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 ant clean jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM