在eclipse中我们在使用 import java.util.Date;语句后便可以在类中建立Date对象,Date date=new Date();并且可以使用其相关的方法,那么如何将自己编写的类封装为jar文件,在使用一定的import语句后能建立相应的对象及使用其中的方法呢?
用记事本编写2个类TestOne和TestTwo,包名为moon.star
TestOne.java
package moon.star;
public class TestOne{
public void fTestOne(){
System.out.println(“this one”);
}
}
TestTwo.java
package moon.star;
public class TestTwo{
public void fTestTwo(){
System.out.println(“this two”);
}
}
将上述TestOne.java和TestTwo.java保存到某个\moon\star目录中
例如E:\chapter\moon\star
并编译它们(打开命令提示符进入E:\chapter\moon\star,输入javac .java)
编译通过会在目录下生成TestOne.class和TestTwo.class,
再编写一个清单文件:hello.mf(Manifestfiles)。
hello.mf
Manifest-Version: 1.0
Class: moon.star.TestOne moon.star.TestTwo
Created-By: 1.6<