2
package company;

public class Employee{
    private int num;

    public Employee(int newNum) {
       setNum(newNum);
    }

    public int getNum() {
        return num;
    }
    public void setNum(int newNum) {
        num = newNum;
    }
}

and there is my driver.

import company.*;

public class PrintEmployee {
   public static void main(String[] args) {
       Employee emp;
       emp = new Employee(10000);
       System.out.println(emp.getNum());
   }
}

First, I compile Employee.java with javac *.java.
Secondly, I am using jar -cf company.jar .\*.class this command to create a JAR file.
After that, I am using javac -cp company.jar PrintEmployee.java this command to compile it but it does not work.

PrintEmployee.java:1: error: package company does not exist
bad class file: C:\Users\user\Desktop\company\company.jar(/Employee.class)

How can I do it...

1 Answers1

2

you are missing package company in the jar file.

mkdir company
mv Employee.java company/
javac company/*.java
jar -cf company.jar company/*.class

then you can run

javac -cp company.jar PrintEmployee.java

without any problem

guleryuz
  • 2,714
  • 1
  • 15
  • 19