You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Phillip Hellewell <ss...@gmail.com> on 2011/01/05 23:50:47 UTC

Copying dependencies' binaries (dlls) for runtime

Is it appropriate / best practice to use the maven-resources-plugin to
copy dlls from target\dependency\bin to target\bin so they will be
where I need them for runtime?

Thanks,
Phillip

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copying dependencies' binaries (dlls) for runtime

Posted by Phillip Hellewell <ss...@gmail.com>.
On Thu, Jan 6, 2011 at 1:03 AM, Anders Hammar <an...@hammar.net> wrote:
> Don't put the configuration in a file outside the pom. A plugin's
> configuration should be in the pom.

The configuration for my plugin will be in the pom of course, but the
configuration of the filesets and other logic to determine some DLLs I
need to copy has to be in separate xml files because they will come
from the dependencies.

I pretty much know what I need to do to write my plugin, and it won't
be that hard, but I'm looking for the best way to have my own xml that
I can easily parse.  And I thought maybe I could re-use the logic the
Maven uses for parsing <resources> into a java.util.List of
org.apache.maven.model.Resource, so that I can re-use the shared code
in org.apache.maven.shared.filtering to do the actual copying.

Here is a longer description of what I'm trying to do.  I want to
create a plugin that will
1. copy dlls/pdbs/etc needed for runtime from specific places below
target\dependency\bin to target\bin.
2. copy other dlls/pdbs/etc needed for runtime from specific places
defined by XML files that come from the dependencies.

The plugin would take the following params:
	sourceDirectory - where dependencies are checked out to (default is
target\dependency)
	sourceBinDirectory - where the binary files live (default is
${sourceDirectory}\bin)
	sourceXMLDirectory - where the binaries.xml files live (default is
${sourceDirectory}\setup-runtime)
	outputDirectory - where to copy binaries to (default is
target\bin\${config}.${platform})
	config - (Debug, Release, or all; defaults to all)
	platform - (Win32, x64, "Any CPU", or all; defaults to all)
	framework - (vc100, dotnet35, dotnet40, silverlight4, silverlight5)

The plugin will have a copy-binaries goal that starts by copying all
the dlls/pdbs/etc that exist in the standard locations to the
outputDirectory:
	1. $sourceBinDirectory/$framework/$config.$platform/*
	2. $sourceBinDirectory/$framework/$config for $platform.*/
	3. $sourceBinDirectory/$framework/$config/*
	4. $sourceBinDirectory/$framework/$platform/* (look for "d" extension
to exclude debug or release depending on config)

The copy-binaries goal will then copy non-standard files (outside
$sourceBinDirectory) by looking for fileset definitions in files named
binaries.xml below $sourceXMLDirectory.  The components that need to
will provide this binaries.xml.

Example binaries.xml file, assuming I mimic the XML schema used by the
assembly plugin (directory is relative to ${sourceDirectory}):
<?xml version="1.0" encoding="utf-8"?>
<binaries>
  <fileSets>
    <!-- Copy all tz files -->
    <fileSet>
      <includes>
        <include>tz/**</include>
      </includes>
    </fileSet>
    <!-- Copy dtSearch 32-bit files if platform is Win32 -->
    <fileSet>
      <platform>Win32</platform>
      <directory>dtSearch\bin\32bit</directory>
      <includes>
        <include>**</include>
      </includes>
    </fileSet>
  </fileSets>
</binaries>

If I pattern after the resources plugin, and can re-use some of that
logic, then the tags will probably be <resources> and <resource>
instead of <fileSets> and <fileSet>.

Phillip

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copying dependencies' binaries (dlls) for runtime

Posted by Anders Hammar <an...@hammar.net>.
Don't put the configuration in a file outside the pom. A plugin's
configuration should be in the pom.

/Anders
On Thu, Jan 6, 2011 at 00:32, Phillip Hellewell <ss...@gmail.com> wrote:

> On Wed, Jan 5, 2011 at 4:24 PM, khaido <kh...@impinj.com> wrote:
> >
> > You might want to look at the maven-dependency-plugin(
> http://maven.apache.org/plugins/maven-dependency-plugin/).  Nice if you
> also need the transitive dependencies.  Also unpack makes it nice to work
> with zip files.
>
> Thanks.  I'm actually already using the dependency plugin to copy and
> unpack the dependencies from the local repo to below
> target\dependency.  But now I need to take a subset of those (the dlls
> needed for runtime) and copy them from target\dependency\bin to
> target\bin.
>
> I'm thinking of writing my own plugin to do the copying, because I
> need some additional logic.  Looking at the mojos in the
> maven-resources-plugin, it looks like I can use shared code from
> org.apache.maven.shared.filtering to do most of the work for me.
>
> My question now is, if I want to define the <resources> in a separate
> stand-alone xml file (actually there will be more than one), rather
> than in the pom.xml, what code/class do I use to read an xml file into
> a java.util.List of org.apache.maven.model.Resource?
>
> Thanks,
> Phillip
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Copying dependencies' binaries (dlls) for runtime

Posted by Phillip Hellewell <ss...@gmail.com>.
On Thu, Jan 6, 2011 at 11:27 AM, Phillip Hellewell <ss...@gmail.com> wrote:
>
> Thanks.  Maybe I should take a closer look at NPanday.  But given all
> the other custom logic I need, I'm pretty sure I'll still need my own
> plugin.

For anyone who is curious, this is what I ended up using for my plugin:

1. org.codehaus.plexus.util.xml.pull.XmlPullParser to parse my XML,
similar to how MavenXpp3Reader parses resources.
2. org.codehaus.plexus.util.DirectoryScanner to match files based on
includes/excludes.
3. org.codehaus.plexus.util.FileUtils to copy files and directories

So basically, the Plexus utilities are what I've been looking for my
whole life :)

Phillip

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copying dependencies' binaries (dlls) for runtime

Posted by Phillip Hellewell <ss...@gmail.com>.
On Thu, Jan 6, 2011 at 11:06 AM, Wendy Smoak <ws...@gmail.com> wrote:
> On Thu, Jan 6, 2011 at 11:56 AM, Phillip Hellewell <ss...@gmail.com> wrote:
>>> You might also be interested in NPanday (http://incubator.apache.org/npanday/) which provides several .NET specific plugins if that's the flavour of DLL you are dealing with.
>>
>> Thanks,but at a quick glance it looks like NPanday is more to help
>> with the build process, and to plug-in to the Visual Studio IDE, so it
>> doesn't look like it will help me copy DLLs with special logic.
>
> With NPanday, you can treat DLLs like normal dependencies.  NPanday
> copies them 'where you need them' automatically.

Thanks.  Maybe I should take a closer look at NPanday.  But given all
the other custom logic I need, I'm pretty sure I'll still need my own
plugin.

So, can anyone answer my actual question of would it work to take an
xml with just a <resources> tag in it, surround it with
<project><build>   </build></project> or whatever to make it a valid
pom, and then use the MavenXpp3Reader to parse that?  Or would it be
better to copy and modify the code I found in parseResource() function
in MavenXpp3Reader?

Another idea is to write an .mdo file, based on the one in the
assembly plugin, and use the modello plugin to generate the Java I
need to parse my xml, but that seems like it might be more work than
just copying the parseResource() function from MavenXpp3Reader.

Phillip

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copying dependencies' binaries (dlls) for runtime

Posted by Wendy Smoak <ws...@gmail.com>.
On Thu, Jan 6, 2011 at 11:56 AM, Phillip Hellewell <ss...@gmail.com> wrote:
>> You might also be interested in NPanday (http://incubator.apache.org/npanday/) which provides several .NET specific plugins if that's the flavour of DLL you are dealing with.
>
> Thanks,but at a quick glance it looks like NPanday is more to help
> with the build process, and to plug-in to the Visual Studio IDE, so it
> doesn't look like it will help me copy DLLs with special logic.

With NPanday, you can treat DLLs like normal dependencies.  NPanday
copies them 'where you need them' automatically.

(Though I'm a bit unsure about what you mean by 'runtime' in your
original question.)

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copying dependencies' binaries (dlls) for runtime

Posted by Phillip Hellewell <ss...@gmail.com>.
On Wed, Jan 5, 2011 at 8:05 PM, Brett Porter <br...@apache.org> wrote:
> Resources are for things packaged and to be used at runtime - that doesn't sound like what you want here.

I think maybe it is because I'm talking about just files (like DLLs)
needed for runtime.  Although they don't need to be packaged.

> This is typically done with a combination of the dependecy & assembly plugin.

I'm already using both of these in the appropriate places.  The
assembly plugin packages up my components (which usually include
headers, libs, and dlls), and the dependency plugin unpackages the
dependencies to below target\dependency.

But now I need another step to copy a subset of the files (e.g.,
dlls), from target\dependency\bin to target\bin that are needed for
runtime.  But I can't use the dependency, assembly, or resources
plugin directly because I need additional logic.  So I'm writing my
own plugin and I just need help figuring out the easiest way to have
my own XML file that specifies the filesets and a couple other things.
 After looking at the mojos in the assembly and resources plugin,
patterning my plugin after the resources plugin looks the easiest /
most promising.

> You might also be interested in NPanday (http://incubator.apache.org/npanday/) which provides several .NET specific plugins if that's the flavour of DLL you are dealing with.

Thanks,but at a quick glance it looks like NPanday is more to help
with the build process, and to plug-in to the Visual Studio IDE, so it
doesn't look like it will help me copy DLLs with special logic.

Phillip

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copying dependencies' binaries (dlls) for runtime

Posted by Brett Porter <br...@apache.org>.
Resources are for things packaged and to be used at runtime - that doesn't sound like what you want here.

This is typically done with a combination of the dependecy & assembly plugin.

You might also be interested in NPanday (http://incubator.apache.org/npanday/) which provides several .NET specific plugins if that's the flavour of DLL you are dealing with.

- Brett

On 06/01/2011, at 11:22 AM, Phillip Hellewell wrote:

> On Wed, Jan 5, 2011 at 4:32 PM, Phillip Hellewell <ss...@gmail.com> wrote:
>> 
>> My question now is, if I want to define the <resources> in a separate
>> stand-alone xml file (actually there will be more than one), rather
>> than in the pom.xml, what code/class do I use to read an xml file into
>> a java.util.List of org.apache.maven.model.Resource?
> 
> Would it work to take read the <resources> tag from my XML, surround
> it with <project><build>   </build></project> or whatever to make it a
> valid pom, and then use the MavenXpp3Reader to parse that?
> 
> I think I found the code where it parses a Resource, and obviously I
> don't want to duplicate that code in my own plugin:
> 
> http://maven.apache.org/ref/2.0.11/xref/org/apache/maven/model/io/xpp3/MavenXpp3Reader.html#4474
> 
> Phillip
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 

--
Brett Porter
brett@apache.org
http://brettporter.wordpress.com/
http://au.linkedin.com/in/brettporter





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copying dependencies' binaries (dlls) for runtime

Posted by Phillip Hellewell <ss...@gmail.com>.
On Wed, Jan 5, 2011 at 4:32 PM, Phillip Hellewell <ss...@gmail.com> wrote:
>
> My question now is, if I want to define the <resources> in a separate
> stand-alone xml file (actually there will be more than one), rather
> than in the pom.xml, what code/class do I use to read an xml file into
> a java.util.List of org.apache.maven.model.Resource?

Would it work to take read the <resources> tag from my XML, surround
it with <project><build>   </build></project> or whatever to make it a
valid pom, and then use the MavenXpp3Reader to parse that?

I think I found the code where it parses a Resource, and obviously I
don't want to duplicate that code in my own plugin:

http://maven.apache.org/ref/2.0.11/xref/org/apache/maven/model/io/xpp3/MavenXpp3Reader.html#4474

Phillip

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copying dependencies' binaries (dlls) for runtime

Posted by Phillip Hellewell <ss...@gmail.com>.
On Wed, Jan 5, 2011 at 4:24 PM, khaido <kh...@impinj.com> wrote:
>
> You might want to look at the maven-dependency-plugin(http://maven.apache.org/plugins/maven-dependency-plugin/).  Nice if you also need the transitive dependencies.  Also unpack makes it nice to work with zip files.

Thanks.  I'm actually already using the dependency plugin to copy and
unpack the dependencies from the local repo to below
target\dependency.  But now I need to take a subset of those (the dlls
needed for runtime) and copy them from target\dependency\bin to
target\bin.

I'm thinking of writing my own plugin to do the copying, because I
need some additional logic.  Looking at the mojos in the
maven-resources-plugin, it looks like I can use shared code from
org.apache.maven.shared.filtering to do most of the work for me.

My question now is, if I want to define the <resources> in a separate
stand-alone xml file (actually there will be more than one), rather
than in the pom.xml, what code/class do I use to read an xml file into
a java.util.List of org.apache.maven.model.Resource?

Thanks,
Phillip

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Copying dependencies' binaries (dlls) for runtime

Posted by khaido <kh...@impinj.com>.
You might want to look at the maven-dependency-plugin(http://maven.apache.org/plugins/maven-dependency-plugin/).  Nice if you also need the transitive dependencies.  Also unpack makes it nice to work with zip files.



From: Phillip Hellewell [via Maven] [mailto:ml-node+3329689-622232288-147165@n5.nabble.com]
Sent: Wednesday, January 05, 2011 2:52 PM
To: Khai Do
Subject: Copying dependencies' binaries (dlls) for runtime

Is it appropriate / best practice to use the maven-resources-plugin to
copy dlls from target\dependency\bin to target\bin so they will be
where I need them for runtime?

Thanks,
Phillip

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]</user/SendEmail.jtp?type=node&node=3329689&i=0>
For additional commands, e-mail: [hidden email]</user/SendEmail.jtp?type=node&node=3329689&i=1>


________________________________
View message @ http://maven.40175.n5.nabble.com/Copying-dependencies-binaries-dlls-for-runtime-tp3329689p3329689.html
To start a new topic under Maven - Users, email ml-node+40176-907978382-147165@n5.nabble.com
To unsubscribe from Maven - Users, click here<http://maven.40175.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=40176&code=a2hhaS5kb0BpbXBpbmouY29tfDQwMTc2fC0xMjUwNjg2MDQ0>.

-- 
View this message in context: http://maven.40175.n5.nabble.com/Copying-dependencies-binaries-dlls-for-runtime-tp3329689p3329746.html
Sent from the Maven - Users mailing list archive at Nabble.com.