• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Maven: Using jars in classpath without defining dependencies

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

Cheers,
-Gunnar
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there and welcome to Javaranch!

It's definitely recommended to add them as dependencies, this can be annoying, but it is a one-off task! That said you can do it, see this for details.
 
Saloon Keeper
Posts: 22291
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gunnar Meyer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Thanks again for your time,
-Gunnar
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic