jar包

需求:

1.在E:\Test中编写两个java类TestPackage1.java和TestPackage2.java,分别属于包pack1和pack2,且TestPackage1.java调用TestPackage2.java的show()方法

2.将两个包存放在E:\Test文件夹下

3.将两个包压缩成merge.jar包,存放在E:\Test文件夹下

4.执行merge.jar中的TestPackage1.class

 

1.定义类

Test1.java

1 package pack1;
2 import pack2.*;
3 class Test1 
4 {
5     public static void main(String[] args) 
6     {
7         new Test2().show();
8     }
9 }

Test2.java

1 package pack2;
2 public class Test2 //定义成共有,以供Test1访问
3 {
4     public void show() //同理可得
5     {
6         System.out.println("Suceess!");
7     }
8 }

2.编译

 

E:\Test>set calsspath=.     必须的

E:\Test>javac -d . Test2.java    必须先编译Test2

E:\Test>javac -d . Test1.java     编译Test1

3.压缩包

 

E:\Test>jar -cf merge.jar pack1 pack2

4.执行包中方法

E:\Test>set classpath=.\merge.jar

E:\Test>java pack1.Test1

 5.dos小技巧:将打印出来的信息显示到文本文件中

 

E:\Test>java pack1.Test1 >E:\1.txt

  

 

 

posted @ 2015-08-04 11:50  洱海  阅读(167)  评论(0编辑  收藏  举报
.First { margin: 10px 0; font-family: 'Microsoft Yahei'; text-align: left; padding: 6px 20px; color: #fff; background: #55895B; font-size: 20px; border-radius: 4px; clear: both; } .Second { margin: 10px 0; font-family: 'Microsoft Yahei'; padding: 6px 20px; background: #93C8A2; color: white; font-size: 18px; border-radius: 4px; clear: both; } .Third { margin: 10px 0; padding: 6px 20px; font-family: 'Microsoft Yahei'; margin: 15px 0; font-size: 16px; color: black; background: #C6EFD2; border-radius: 4px; clear: both; } .note { margin: 10px 0; padding: 15px 20px 15px 60px; background: #FCFAA9 url('http://images.cnblogs.com/cnblogs_com/libaoheng/305804/o_yellow-pin.png') no-repeat 20px 0; font-size: 15px; font-family: 'Microsoft Yahei'; box-shadow: 0 0 8px #aaa; clear: both; } .demo { text-align: left; padding: 6px 20px; overflow: auto; border-radius: 4px; background: orange; color: #fff; font-size: 16px; clear: both; } .cnblogs_Highlighter { border: solid 1px #ccc; clear: both; } .cnblogs_code { background: #EFFFF4; border: solid 0px #939393; font-size: 14px; clear: both; padding: 10px 20px; } .cnblogs_code pre { font-size: 14px; } .cnblogs_code span { font-family: Courier New; font-size: 14px; }