Why do Java source files go into a directory structure?

Posted by bdhar on Stack Overflow See other posts from Stack Overflow or by bdhar
Published on 2010-06-09T10:09:47Z Indexed on 2010/06/09 10:12 UTC
Read the original article Hit count: 236

Suppose that I am creating a Java project with the following classes

  1. com.bharani.ClassOne
  2. com.bharani.ClassTwo
  3. com.bharani.helper.HelperOne
  4. com.bharani.helper.support.HelperTwo

with files put immediately under the folder 'src'

  1. src/ClassOne.java
  2. src/ClassTwo.java
  3. src/HelperOne.java
  4. src/HelperTwo.java

and compile them using the command

$ javac src/*.java -d classes (assuming that classes directory exists)

The compiler compiles these files and put the class files in appropriate sub-directories inside the 'classes' directory like this

  1. classes/com/bharani/ClassOne.class
  2. classes/com/bharani/ClassTwo.class
  3. classes/com/bharani/helper/HelperOne.class
  4. classes/com/bharani/helper/support/HelperTwo.class

Because the spec mandates that the classes should go inside appropriate directory structure. Fine.

My question is this: When I use an IDE such as Eclipse or NetBeans, they create the directory structure for the source code directory ('src' directory here) also. Why is that? Is it mandatory? Or, is it just a convention?

Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about source-code