I’ve been using Java for my “home projects” for a while and now there’s a need to make some of my projects available through the repositories like github or Google Code.
As long as I’m the only developer for the project and as long as I always work in Eclipse, there are absolutely no questions about building and running it. Everything just work fine. The question is basically, what do I do if someone asks me to share? 🙂
The first thing to do is, making the project buildable with tools like Maven. In this case, no matter if someone has Eclipse installed, or prefers IDEA, he may just download my project and build using Maven. Or, import to Eclipse/IDEA and build.
So, to clarify the question, here are 2 points:
- What should my directory structure look like? Folders like src, bin, anything else?
- What is the way my application should run? For instance, my application requires log4j in order to run. Maven resolves this dependency, when building the package. But when the package is built, you should manually provide the path to you log4j (with
java -cp ...) – what’s the way to eliminate this requirement if I’d like to just provide .sh and .cmd scripts for user’s convenience?
From my personal experience, maven is the best available tool for building and managing dependencies, so my answers for your questions are all about maven. Also, with maven you need to provide only pom.xml file containing definition of dependencies and project build configuration. Project you share does not need to contain any JARs inside, as it used to be with ant based projects.
As in a standard maven project 🙂 (http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)
should be also in the com.company package, it introduces some order
and sometimes makes testing easier)
message.propertiesfile serving internationalizationThere are also other directories, such as src/main/webapp – all of them are described in the maven docs.
Maven takes care about all of these things, following your configuration defined in pom.xml file. If you program requires some extra-libraries, maven will download it for you, and place in the package containing your application. If, for example some dependencies will be provided by your application server (log4j JAR), you can also set that dependency is gonna be provided and then, it will be available for running application, for unit tests, but it will not be places in the final package.
What is additional great feature provided by maven is build profiles. You can for example use some setting in the day-to-day development mode, but in case of building package for production, other settings will be used.