首页 > 代码库 > java程序编译

java程序编译

Empoyee.java

package Company;public class Empoyee{    String name = "";    public Empoyee(String name)    {        this.name = name;    }    public String getName()    {        return this.name;    }}

编译

# 开发第三方库cd ~/src/Companymkdir sourcemkdir classes# 编写代码并编译cd sourcejavac -d ../classes Empoyee.java# 生成Company.jar cd ../classesjar -cvf Company.jar Company/*.java

 

Hello.java

import Company.Empoyee;public class Hello{    public static void main(String args[])    {        Empoyee e1 = new Empoyee("lishujun");        System.out.println(e1.getName());    }}

编译

# 在代码里引用第三方库进行开发cd ~/src/hellomkdir classesmkdir sourcemkdir lib# 编译引用第三方库程序cd sourcejavac -d ../classes Hello.java -cp ../lib/Company.jar# 执行引用第三方库程序cd ../classesjava -cp .;../lib/Company.jar Hello