This paper studies a just-in-time job-shop scheduling problem (JITJSSP) in which each operation has an earliness cost or a tardiness cost if it is completed before or after its due date and the objective function is to minimize the total earliness and tardiness costs of all operations. In order to solve this problem, an improved genetic algorithm (IGA) is introduced in this paper. IGA utilizes an operation-based scheme to represent schedules as chromosomes. Then, each chromosome is processed through a three-stage mechanism. Firstly, the semi-active decoding process is employed to expand the search space of solutions and guarantee comprehensive solutions. Secondly, the greedy insertion mechanism for tardy operations is executed to move the tardy operations left to the appropriate idle time to reduce the tardiness costs. Finally, the greedy insertion mechanism for early operations is proposed to shift the early operations right to the suitable idle time to decrease the earliness costs. After the maximum number of generations is reached, IGA continues with selection, crossover and mutation. The experimental results finally show that most of solutions on the benchmarks are improved by our algorithm.