Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

best practices for package directory structure?

843785Nov 25 2008 — edited Nov 25 2008
I've only compiled a few java programs & while I find the language itself very easy to adapt to from C++ and Javascript, I get confused about the directory structure and classpaths & such.

My main method of operation is to build small tools and test projects, and I would like to follow good practices for organizing my directory structure, so it will (a) work well with java, and (b) work well with my source control software.

Let's say I am developing packages named "com.example.test.test1", "com.example.test.test2", "com.example.tools.flapper", and "com.example.tools.spinner".

I know I can use this structure:
/java/test/test1/com/example/test/test1/* (files for com.example.test.test1 including test1.java)
/java/test/test2/com/example/test/test2/* (files for com.example.test.test2 including test2.java)
/java/tools/flapper/com/example/tools/flapper/* (files for com.example.tools.flapper including flapper.java)
/java/tools/spinner/com/example/tools/spinner/* (files for com.example.tools.spinner including spinner.java)

But the directories seem unnecessarily deep & lead to a hassle in source control that makes it difficult to browse.

Can I use this? and if so, how do I run "javac" and "jar" properly to compile/jar-ify each package?
/java/com/example/test/test1/* (files for com.example.test.test1)
/java/com/example/test/test2/* (files for com.example.test.test2)
/java/com/example/tools/flapper/* (files for com.example.tools.flapper)
/java/com/example/tools/spinner/* (files for com.example.tools.spinner)

also is it recommended to leave the .class files in the same dirs as the .java files, or better to have a separate tree for compiled .class files?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 23 2008
Added on Nov 25 2008
4 comments
1,068 views