Wednesday, October 21, 2009

Create Java classes' package structure

While Compiling java classes it is sometimes required to get class files in proper structured format.

package com.start;
public class test{
//some functional code
}
Following command can be used:
java -d . test.java
It will create package structure com/start/test.class.
Here dot(.) specifies current directory so package will be create in current directory ex: c:/root/com/start/test.class, i.e whereever java file is present. "d" option is used to specify destination where class files will get generated. Without this option class file will get generated in same directory without package structure. For generating class files in different directory along with pacakge structure you can use following command:
java -d Destinationdirectory test.java
here Destinationdirectory can be any valid directory path like c:/root.

1 comment: