I would like to know if there is some uniform way to organize my packages in my directory structure. I'm on a Windows machine using javac as my compiler and a text editor (gvim) to create all my .java files. I am learning how to use packages, and I want to set all of my classes up in the same package hierarchy (org.timallen.foo, org.timallen.bar.utils, etc-- BTW, that really is my domain). How should I set this up on disk? Keep in mind that I eventually might start using Ant to maintain my classes. Does any of this change if I decide to distribute my classes in a jar file? Finally, how do I have to set my classpath to support all of this? Thanks in advance.
I have everything under one directory (D:\user\java\sources in my case; you can do what you want...). Then, all of my source code goes there. So, for example, if I have a class called "CFile" in a package "com.coolskill.foundation.io", the code is located at: D:\user\java\sources\com\coolskill\foundation\io\CFile.java D:\user\java\sources\com\coolskill\foundation\io\CFile.class When I distribute my classes as .jar files, I simply package them into a jar file. As far as setting the classpath, on my machine the classpath includes D:\user\java\sources, since that is where all my code is. On a machine that has your code distributed, you muct include the .jar file in the classpath (eg. "C:\Program Files\CoolApp\libs\Foundation.jar") -------------------- *Cavaets: 1). I've not used ANT, so I can't say how this setup affects Ant 2). IDEs such as Eclipse do not allow the same directory to be in multiple projects. I use NetBeans (NetBeans/SUN ONE, near as I can tell, is the only IDE that does allow this). Since I do as much work outside of an IDE as in one, I lump everything in one root directory so that I'm not constantly fiddeling with my CLASSPATH.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
As your projects start to get more complex, you're really going to want to keep your source files seperate from your generated files, including your compiled class files. At a very minimum I'd create a classes directory to keep your compiled class files seperated from your source. You'd have something like
This is the "standard" way of doing things. As your builds get more complicated there are more things you will need to do, like build for testing, jaring, packaging for deployment, etc, and having a well-organized, standard hierarchy will make your life a lot easier. Also, to set your classpath you can then just add your "classes" directory to your classpath, along with any other lib directory or jar files your project is using. [ May 28, 2003: Message edited by: Rob Ross ] [ May 28, 2003: Message edited by: Rob Ross ]
I don't recall where I got this, but something made it sound like a common convention, so I re-orged my stuff like this: src - Java source classes - classes generated by Ant compiles distribution - jars & such that I generate docs - JavaDoc that I generate lib - other people's jars & such ant - Ant scripts I do most of my compile & test right in the Forte IDE which does not use all these directories. I build for execution outside the IDE with Ant. The Ant scripts put things in the classes, docs and distribution directories. Anybody else?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi