Empoyee.java
package Company; public class Empoyee { String name = ""; public Empoyee(String name) { this.name = name; } public String getName() { return this.name; } }
编译
# 开发第三方库 cd ~/src/Company mkdir source mkdir classes # 编写代码并编译 cd source javac -d ../classes Empoyee.java # 生成Company.jar cd ../classes jar -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/hello mkdir classes mkdir source mkdir lib # 编译引用第三方库程序 cd source javac -d ../classes Hello.java -cp ../lib/Company.jar # 执行引用第三方库程序 cd ../classes java -cp .;../lib/Company.jar Hello
java程序编译
时间: 2024-10-07 12:02:13