Here's one standard layout and associated command lines for a prototypic
"foo" project:
${PROJECTS}/foo/
|- build/classes/
|- src/com/lewscanon/foo/
|- Foo.java
Lew is suggesting is a highly sensible layout. I post only to mention that
there is a popular variant that makes it slightly more complicated:
foo/
build/
classes/
src/
main/
/com/lewscanon/foo/
Foo.java
test/
/com/lewscanon/foo/
FooTests.java
The idea is to keep unit test code in a completely separate folder
hierarchy to the main code. That way, during development you can compile
the whole lot:
javac -g -Xlint -d build/classes/ $(find src -name \*.java)
And for a release, just the main code:
javac -d build/classes/ $(find src/main -name \*.java)
Which is handy.
Whether you use the simpler or more fiddly versions, you usually place
other directories like so (at least, i think so - i welcome corrections):
foo/
build/
classes/
src/ -- described elsewhere
resources/ -- resources which should be on the classpath, structured as src/
lib/ -- JARs on which your code depends
bin/ -- launch scripts (not really standard?)
Some styles put resources inside src directory, but separated from actual
source code. Maven likes to do this:
foo/
src/
main/
java/
resources/
test/
java/
resources/
And so you'll see that an awful lot. It seems overly complicated to me,
though. I like my src directory to contain source code and nothing but.
Typical build commands for the former setup:
# build and run in development
cd $PROJECTS/foo
rm -rf build
mkdir -p build/classes
javac -g -Xlint -d build/classes $(find src -name \*.java)
# run the unit tests:
java -cp build/classes:resources/main:resources/test:lib/bar.jar:lib/baz.jar:lib/junit.jar org.junit.runner.JUnitCore com.lewscanon.foo.FooTest
# run the app:
java -cp build/classes:resources/main:lib/bar.jar:lib/baz.jar com.lewscanon.foo.Foo
# build for release
cd $PROJECTS/foo
rm -rf build
mkdir -p build/classes
mkdir -p build/jar
javac -d build/classes $(find src/main -name \*.java)
cp -pr resources/main/* build/classes
jar cf build/jar/foo.jar -C build/classes *
Note that this is off the top of my head, so E&OE!
tom