如何使用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命令的问题?
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命令的问题?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货