Using Maven 2, is there a way I can list out the jar dependencies as just the file names?
mvn dependency:build-classpath
can list the jar files, but that will include the full path to their location in my local repository. What I need is essentially just a list of the file names (or the file names that the copy-dependencies goal copied).
So the list I need would be something like
activation-1.1.jar,antlr-2.7.6.jar,aopalliance-1.0.jar etc...
ideally as a maven property, but I guess, a file such as build-classpath can generate will do.
What I am trying to achieve is writing a Bundle-ClassPath
to an otherwise manually maintained MANIFEST.MF file for a OSGi bundle. (You shouldn't need to understand this bit to answer the question.)
To clarify: The question is not about how to write manifest headers into the MANIFEST.MF file in a jar (that is easily googleble). I am asking about how to get the data I want to write, namely the list shown above.
Maven can build the classpath in your manifest automatically: http://maven.apache.org/guides/mini/guide-manifest.html
It's a configuration of the Maven archive plugin.
Here's the command you're asking for
For large projects it can output a lot of text. I assume that you want to check that dependency tree contains a certain dependency, so you don't need a full list.
Here's how you can filter output on Windows:
And here's how you can do it on Linux:
Maven way to filter the dependency tree (works in Windows cmd, MacOS and Linux shell):
Maven way (Windows PowerShell):
Have you looked at the Apache Felix project? It has a whole mess of plugins, including a bundle plugin that should do what you want.
Also, have you tried the
<addClasspath>
tag with<manifestFile>
? That should have the desired effect of merging the classpath into your manifest.This command will generate the dependencies tree of your maven project:
I am sure that you will like the result :-)
As best as I can tell, you can't get exactly that output, with the commas and no spaces. Both via the command line and via the pom.xml file, the maven-dependency-plugin or the CLI freaks out if you specify spaces or the '' (empty string) as a substitute with either
pathSeparator
orfileSeparator
. So, you may be forced to reach something of a compromise. You canHowever, that should get you a full list, separated by
'::'
instead of just','
, but it works. If you run:and attach this to the
generate-resources
phase and filter that resource later by setting the correct property in theprocess-resources
phase of the lifecycle, you should be able to get just the comma.You can see the full list of options at: http://maven.apache.org/plugins/maven-dependency-plugin/build-classpath-mojo.html
Here is an awk script to pipe
mvn dependency:list
:You can
| sort
if you want to sort by name, or| tr '\n' ':'
to format it to a classpath.mvnfmt.awk
is: