Java 用ant脚本编译库

Java 用ant脚本编译库,java,ant,jar,import,compilation,Java,Ant,Jar,Import,Compilation,我创建了包(项目)点,其中包含类正方形,矩形,点,圆形和直线。它们是具有用于创建所述对象的构造函数的简单类。 从要点上讲,你这样称呼他们: Point p1 = new Point(0,3); package simpleapp; import point; public class SimpleApp{ public static void main(String [] args){ //Please press 1 to create Point //

我创建了包(项目)
,其中包含类
正方形
矩形
圆形
直线
。它们是具有用于创建所述对象的构造函数的简单类。 从要点上讲,你这样称呼他们:

Point p1 = new Point(0,3);
package simpleapp;

import point;

public class SimpleApp{



  public static void main(String [] args){


     //Please press 1 to create Point
     //Please specify x and y axis:
     //i will select the type of object and create it
     //Object o = new whichObject(1)(x,y); 

  }
}
我应该写一个程序,要求用户选择他想要创建的对象并设置其几何图形,我只能使用我的点包作为库

1) 创建
simple graphics.jar
库。 我删除了
Point
包中的main方法,并设法从
Point
包中生成
simple graphics.jar
executable.jar文件

2) 我被要求创建一些ant脚本,从它的源文件编译这个库并生成.jar文件,但是,我不知道如何做,如果我还没有在1)中完成,关于ant脚本的教程对我来说不是很清楚。我想我应该用两种方式来做,在NetBeans中选择product.jar选项,并在某个地方使用这个ant脚本

3) 我应该能够使用
java-jar simple graphics.jar运行2)生成的.jar文件,我应该如何在NetBeans中运行它,还是应该使用cmd?我在W7

编辑: 谢谢你的剧本,看看吧,我肯定写不出所有这些

如何在程序中使用此库?已解决-如下所示:

Point p1 = new Point(0,3);
package simpleapp;

import point;

public class SimpleApp{



  public static void main(String [] args){


     //Please press 1 to create Point
     //Please specify x and y axis:
     //i will select the type of object and create it
     //Object o = new whichObject(1)(x,y); 

  }
}
点类在包点中,其他类非常相似:

package point;

public class Point{

 double x;
 double y;

 public Point(double a, double b){
  x = a;
  y = b;
 }

 public Point(){
  x = 0;
  y = 0;
 }

 public double distance(Point p){
   return Math.sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y-y));
 }
}

这里有一个非常基本的Ant脚本(
build.xml
),可以将Java文件编译成类文件,并将它们打包到JAR文件中,前提是Java源文件位于子目录
src
中。请注意,这只是一个起点

<project name="Point-Library" default="build">

  <property name="src.dir" value="src" />
  <property name="build.dir" value="build" />
  <property name="jar.name" value="simple-graphics.jar" />

  <target name="build" depends="prepare, compile, jar" />

  <target name="prepare" description="Creates the build folder">
    <mkdir dir="${build.dir}" />
  </target>

  <target name="compile" description="Compiles the Java source files">
    <javac srcdir="${src.dir}" destdir="${build.dir}" />
  </target>

  <target name="jar" description="Packs the compiled Java classes into a JAR file">
    <jar basedir="${build.dir}" destfile="${jar.name}" />
  </target>

</project>

对于使用
类的客户机代码来说,无论它们的源代码是项目的一部分,还是您只导入包含
类文件的JAR文件,都没有区别。

谢谢,您是救命恩人!我成功地完成了我的课程,并将在假期学习和编写脚本,因为我将来无论如何都需要它们。