Jar 初步
前言
>jar 是 java 文件中一种文件格式,用于将 .java 文件编译的字节码文件打包成 jar。给 Java 应用打包
1. 新建一个 java 源文件
``` package cn.szxy;public class Student {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Student(String name, int age) {
super();
this.name = name;
this.age = age;
}
public Student() {
super();
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + "]";
}
}
<h2>2. 将 Java 源文件编译成字节码文件</h2>
> jar 命令
![](https://img2018.cnblogs.com/blog/1569987/201903/1569987-20190302234143358-1471302582.png)
![](https://img2018.cnblogs.com/blog/1569987/201903/1569987-20190302234004019-1088933608.png)
在 cn 上级目录中,执行 `jar -cvg myJar.jar cn`
![](https://img2018.cnblogs.com/blog/1569987/201903/1569987-20190302233802830-2036493642.png)
<h2>3. 导入Eclipse 中,并添加到构建目录</h2>
![](https://img2018.cnblogs.com/blog/1569987/201903/1569987-20190302235117798-354992785.png)
<h1>Last</h1>
>这样就导入 jar 包完成。