I built a stand-alone Java application that has a bunch of dependencies (Apache Commons libs, etc) as well as a dependency on the Spring framework, which in turn has a bunch of dependencies.
I built this in Eclipse, where it runs fine. Now I need to deploy it to production and so I'm trying to figure out the best way to package it with all dependencies and also how to even invoke the thing (it will be invoked from the command line).
The brute-force way would be to export my project as a jar, find all the dependent jars (and their dependencies!), copy them to a common directory, write a shell script that includes every one on the classpath and run it. Obviously that seems stupid and tedious.
Should I use Ant, Maven? Should I package all of the dependent Spring jars into one big file? Any tips on dealing with this would be helpful.
You can use a launcher that sets the classpath correctly. Then, you'll have much more flexibility to package your JARs. You could easily put them all in a directory, which is much cleaner than creating a "bastard" ueber jar ...
One of such launcher is commons-launcher.
All this Maven love and no one mentions Ivy? Oh dear!
Well, here's Ant Ivy and here's comparison to Maven2. Please take a look at it too before going with almost everyone is suggesting.
You could also use Gradle and here is how you can do it there:
A lot of your concerns disappear if you make your JAR executable and add a manifest including ClassPath. You do have to ZIP the JAR and its dependencies together, unfortunately, but your CLASSPATH problems are taken care of.
What about creating an OSGi bundle? I haven't looked into it myself yet, but it's supposed to be the next thing for packaging Java apps. It's used in app servers like Spring's dm Server. Perhaps it can help you as well.
With Ant you could do something along the following:
For managing your dependencies, you could go with Ivy. Much like Maven, it is able to retrieve dependencies at build time from whichever repositories you configure, including Maven repositories or your own private repository.
We are using Maven 2 with m2eclipse plugin; works pretty good. Plugin has a dependency graph view, will show conflicts etc.
Now, if you want to package all of your dependencies into the single jar, you can check out Jar Jar Links (no kidding!).