首先写了一个hello.class
发现需要在类前加入package 目录声明然后别的类才能访问
//d:\test\hello.java
package hell;
public class hello
{
public void fun()
{
System.out.println("hello");
}}//d:\test\test.java
import hell.hello;
class test
{
public static void main(String[] args)
{
hello h=new hello();
h.fun();
}
}
然后javac -d .hello.java
然后javac test.java
这样编译和运行是可以的,现在我将hello.class类打包
jar -cvf hel.jar hell
这时候我test类需要怎么写import 来使用hello类??????
发现需要在类前加入package 目录声明然后别的类才能访问
//d:\test\hello.java
package hell;
public class hello
{
public void fun()
{
System.out.println("hello");
}}//d:\test\test.java
import hell.hello;
class test
{
public static void main(String[] args)
{
hello h=new hello();
h.fun();
}
}
然后javac -d .hello.java
然后javac test.java
这样编译和运行是可以的,现在我将hello.class类打包
jar -cvf hel.jar hell
这时候我test类需要怎么写import 来使用hello类??????
不变
项目中需要添加相应jar包
我把import hell.hell.hello;
import hell.hello;都试了下,都不可以,找不到类
及java -classpath hel.jar test
但是
java -classpath hel.jar test 却运行错误