Cobertura is very good code coverage tool. It supports command line usage as well as ant tasks.
You need to instrument the application (it modifies the bytecode). Then you need to run your unit tests. Cobertura captures the test coverage in a binray file (which is generated during instrumentation). You can then generage report. Cobertura generate very beatiful HTML reports. For all these you have command line tasks and ant tasks.