본문 바로가기

java helloworld

[리눅스] Classpath import

2018. 4. 27.


불러오는 형으로 main 이 없다.


 Printer.java

 package test;  test 에 존재한다.

public class Printer {
    public void print(){
        String html = "<html><body> <h1>my html</h1> </body></html>";
        System.out.println("html:" + html);
         
    }
}


test에 Printer 를 불러온다.


 Hello.java

 import test.Printer;

public class Hello {
         
         
        public static void main(String[] args)
        {
            Printer printer = new Printer();
            printer.print();  
            System.out.println("Hello world!!!");
        }
}


실행


[root@localhost file]# javac Hello.java

[root@localhost file]# javac -d . test/Printer.java

[root@localhost file]# java Hello

html:<html><body> <h1>my html</h1> </body></html>

Hello world!!!



댓글