I have quite a lot of jars which I need to run JUnit tests with Maven. Unfortunatly I would have to add them all as dependencies by hand. As it would take AGES doing so, I would rather include them by providing the path on my local harddrive. They are contained in a single folder anyway.
Is there any possibility to add an entry to the classpath Maven uses?
You'd still have a lot of work to do, since you can't add all the JARs in a directory to the classpath in a generic way, you have to add each one individually.
You will have to define them as dependencies to get Maven to pull them into its test classpath. You can avoid adding them to the repository, if you prefer and just make them external references, but I forget the scope value that does that.
Here's a little snippet I use to add external Jars to Maven control. A variation of it could be used to generate the dependency XML. I just do a straight-up directory list to generate the basic input file, then edit it to add the details.
An IDE is no substitute for an Intelligent Developer.
You might not have to list all of the JARs as dependencies. Your code might only directly require a few JARs which in turn have dependencies on other JARs, and so on. Provided those dependencies are properly configured within the Maven repository, specifying the first-level dependencies in your pom should suffice.
The JBoss team recently released a tool, TattleTale, that can be used to track dependencies and transitive dependencies, it might help you with this.
thanks for your replies. As I had about 200 jars (provided by a liferay portal installation btw), adding them all as dependencies was not a realistic approach, as it would require lots of manual work. Finding out which of these .jars I actually need would reduce the number of dependencies, but will most likely take even more time.
Fortunatly the surefire plugin, which is responsible for running tests in Maven, provides an additional classpath functionality which does (almost) exactly what I wanted. As Tim already mentioned, you can't just add all .jars contained in a directory, but have to specify every single one by itself.
So I did the following:
and copy/pasted the content in my pom.
Definitely not a very elegant solution, but it saved me a couple of hours.