当前位置:编程学习 > JAVA >>

最基本的java问题:java 命令调用jar包

如何使用java命令调用已经存在的jar包?

我用命令行写了一个简单的类包,使用jar命令打成jar文件,确不能调用,希望高手能够指点一下

源文件目录结构
test
  |___com
  |          |__test.java
  |___hello.java
源程序如下:

test.java的源程序:
package com;
public class test{
        public void testX(){
                System.out.println("this is test");
        }
}
hello.java的源程序
class hello{
        private static com.test t = new com.test();
        public static void main(String args[]){

                t.testX();
                System.out.println("hello world!");
        }
}



1 、在test目录下执行
      javac com/test.java 
      javac hello.java
     编译通过
    执行 java hello 正确输出结果
2.  jar -cvf  com.jar com/test.class
     mv com com_bk
     执行java hello 输出错误
     执行 java hello -jar com.jar    java hello -cp com.jar 都输出错误

请问个问高手,如何使用java命令调用一个已经存在的 jar包? 是java命令的问题还是jar命令的问题?
      

--------------------编程问答-------------------- 用jar 命令打包时,要将你的两个.class 都打包在com.jar中  正确的应该是 jar cvf classes.jar Text.class Hello.class 否则com.jar中根本没有你要执行的hello类
--------------------编程问答-------------------- 有什么工具打的jar?
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,