You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by David Weintraub <qa...@gmail.com> on 2009/01/28 14:29:56 UTC

Maven Assemblies

I'm building a JAR file that needs to be packaged with some shell
scripts and some configuration files. The shell scripts will be in a
"bin" directory, the configuration files will be in a "conf"
directory, and I'd like the jar in the "lib" directory with any of the
dependency jars mentioned in the POM.

I've read about Assemblies in Maven -- The Definitive Guide, but I am
a little confused about them. It looks like the Assembly is separate
from the POM. Is this true? If it is separate from the POM, where is
it suppose to live, and how does the POM refer to it?

I figure this is a pretty standard setup for a standalone JAR
application, but I haven't seen any examples of this particular setup.

--
David Weintraub
qazwart@gmail.com

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


RE: Maven Assemblies

Posted by "Edelson, Justin" <Ju...@mtvstaff.com>.
The assembly descriptor (i.e. the file that defines the directory structure and contents of the assembly) is a separate file from the POM. They are typically placed in src/main/assembly/.
 
See http://maven.apache.org/plugins/maven-assembly-plugin/usage.html for examples of how to configure the assembly plugin in your POM to point to the assembly descriptor file name.
 
Justin

________________________________

From: David Weintraub [mailto:qazwart@gmail.com]
Sent: Wed 1/28/2009 8:29 AM
To: Maven Users List
Cc: jkeck@solbright.com
Subject: Maven Assemblies



I'm building a JAR file that needs to be packaged with some shell
scripts and some configuration files. The shell scripts will be in a
"bin" directory, the configuration files will be in a "conf"
directory, and I'd like the jar in the "lib" directory with any of the
dependency jars mentioned in the POM.

I've read about Assemblies in Maven -- The Definitive Guide, but I am
a little confused about them. It looks like the Assembly is separate
from the POM. Is this true? If it is separate from the POM, where is
it suppose to live, and how does the POM refer to it?

I figure this is a pretty standard setup for a standalone JAR
application, but I haven't seen any examples of this particular setup.

--
David Weintraub
qazwart@gmail.com

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




Re: Maven Assemblies

Posted by David Weintraub <qa...@gmail.com>.
On Thu, Jan 29, 2009 at 5:37 AM, Karl Heinz Marbaise <kh...@gmx.de> wrote:
> Hi David,
>>
>> Thanks for your help. I kept seeing the assembly file referenced, but
>> nothing too much on where it should be.
>
> http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)
>
> Isn't this enough ? Or do i misunderstand things ?

That was handy, but when you're reading what is suppose to be the
definitive Maven reference book on Assemblies, and the book doesn't
mention whether or not the Assembly file is suppose to be a separate
file or where it is stored... Well, you can see why I can get
frustrated.

There may be a lot of information about Maven out there, but it can be
difficult to track down. For example, I spent hours on the
distribution plugin:
<http://maven.apache.org/maven-1.x/plugins/dist/goals.html> which I
found doing a Google search. I just couldn't get it to work. I finally
decided that maybe I have to put the plugin into my local repository,
went to the download page and suddenly realized not one of those links
points to a downloadable distribution plugin file. Each one was one
404 error after another. (Yes, I now realize that this is a Maven 1.x
plugin).

When I went up the Maven web page hierarchy, I discovered that this
plugin was not listed.  <http://maven.apache.org/plugins/index.html>.
So, I then looked at the Packaging Types/Tools since a tarball is a
type of package. I then played with the shade type since it says this
is an "Uber-Jar", I thought maybe that's a way to package things
instead of using tarballs or zip files. Spent another few hours
playing with that.

It took me a while to realize what I wanted to do was to create an
"Assembly". It is certainly difficult to look at the description of an
Assembly on Maven's plugin page to realize that this would be a tool
you need in order to actually build a tarball or zip file. It isn't
even listed under packaging tools.

However, once I realized I wanted to create an Assembly, I could start
reading the chapter on Assemblies in Maven -- The Definitive Guide.
But as I mentioned above, the book doesn't seem to mention where
assembly files are stored or even if they are a separate file from
your POM.

It isn't that I am new at using open source software world. Nor, do I
expect to be trained or have people do my work for me. But, Maven is
an extremely complex piece of software and the documentation is not
well organized.

Take a look at Subversion. One of the reasons Subversion has done so
well is that it has excellent documentation. The definitive Subversion
book isn't merely a reference, but a well written step-by-step manual
explaining how Subversion is used. It then goes through
administration, explaining possible gotchas, and gives some nice
examples. The FAQ section is quite clear.

Ant's documentation isn't quite as nice, but at least it gives some
nice examples on how the various tasks are used. It took me a while to
learn Ant, but I was able to through the web page. Plus, there are a
lot of excellent books on Ant.

The whole purpose of Maven was to eliminate the need for me, the CM,
to do the build scripting. I've spent most of my career writing or
helping developers to write makefiles and later on Ant build scripts.
Most of the time, it falls on me to do this type of work. Maven was
suppose to be a way for developers not to worry about how builds
happen because Maven will take care of it.

Now, I am sitting around and writing Maven POMs for my developers.
And, because the way Maven works, I now have to fiddle with the source
code, something I didn't have to do with Ant and Makefiles. Our
developers hate Maven and simply find it incomprehensible.

Here's the latest request from one of our developers:

> Thanks for arranging the folder structure to generate
> deployable artifact as per requirement. We have taken
> latest code from SVN. We need following change in
> generated 'target' folder when we run the 'mvn compile'
< command.

> 1)     Generated 'target' folder contains 'test-classes'.
> But some of the test cases are failing because they have
> dependency on 'conf' and 'data' folders. Can you please
> modify the maven script such a way that it will put 'conf'
> and 'data' into 'target\test-classes\'

Why in the F in RFTM am I responsible for this? I was doing this for
developers in Ant build.xml files. Maven is suppose to take me out of
the picture!

So, please understand my frustration. I am not a developer, and this
is the first time I am working with Maven. Once you get the hang of
everything in Maven, it might be easier to understand and tweak things
the way you want. But, Maven is a difficult piece of software to
understand, and the documentation for Maven is still in a rather
preliminary state.

>
>> There are two issues I am having:
>>
>> 1). In the tarball, the "lib" directory is owned by build/user, but
>> the bin and conf directory is owned by 0/0. Is there a way to set
>> this? I didn't see anything in the Assembly settings.
>
> http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_fileSet
> You should take a look at the filemode ...
> Hm. under which user are you running maven ?

I actually am using filemode, and it is setting the file mode for
these files. However, it seems that the username and usergroup are
being set to 0/0. I don't think this is due to the filemode parameter
because this was happening before I used it.

And, yes, the username and groupname are being set on the lib folder
to the username and groupname I am logged in as. But, the question is
why does the "lib" folder get set to build/users while the bin and
conf get set to 0/0? And, how can I set this? In Ant, there were
parameters in the tar task that allowed me to set the user and group.
I didn't see anything in the Maven assembly parameters..

>
>> 2). My boss wants to know why is the assembly file called bin.xml. I
>> told him because the assembly file is a "bin" type, and you name the
>> assembly file after the assembly type. He wants to see documentation
>> to this effect. Is there such documentation? I know you can call your
>> assembly file anything you want, but if this is the Maven standard, I
>> want to stick with it.
>
> First you can call it the way you like but there are some defaults in there
> http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html#descriptorRefs
>
> Or in Maven: The definitive Guid at section "Predefined Assembly
> Descriptors"...you can see things linke bin are referenced...

Once I saw what Assemblies were, I was able to search for assembly
files that happen to be on the Internet. I found a lot of examples,
and it became obvious that they were named bin.xml. After a while, I
realized why since you can have multiple assemblies, and this assembly
is a "bin" type.

Unfortunately, my boss thought the name was confusing. I pointed out
this was "standard" practice and he wanted to see the actual written
standard.

I think I convinced him why it is done that way. I pointed out that
the file is already stored in a directory called "assemblies", and
that projects can have multiple assembly files (for example, source
code distribution, and tarball distribution. He was reasonably happy
with that.

--
David Weintraub
qazwart@gmail.com

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


Re: Maven Assemblies

Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi David,
> Thanks for your help. I kept seeing the assembly file referenced, but
> nothing too much on where it should be.
 
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)

Isn't this enough ? Or do i misunderstand things ?

> There are two issues I am having:
> 
> 1). In the tarball, the "lib" directory is owned by build/user, but
> the bin and conf directory is owned by 0/0. Is there a way to set
> this? I didn't see anything in the Assembly settings.
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_fileSet
You should take a look at the filemode ...
Hm. under which user are you running maven ?

> 2). My boss wants to know why is the assembly file called bin.xml. I
> told him because the assembly file is a "bin" type, and you name the
> assembly file after the assembly type. He wants to see documentation
> to this effect. Is there such documentation? I know you can call your
> assembly file anything you want, but if this is the Maven standard, I
> want to stick with it.

First you can call it the way you like but there are some defaults in there
http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html#descriptorRefs

Or in Maven: The definitive Guid at section "Predefined Assembly 
Descriptors"...you can see things linke bin are referenced...


Kind regards
Karl Heinz Marbaise
-- 
SoftwareEntwicklung Beratung Schulung    Tel.: +49 (0) 2405 / 415 893
Dipl.Ing.(FH) Karl Heinz Marbaise        ICQ#: 135949029
Hauptstrasse 177                         USt.IdNr: DE191347579
52146 Würselen                           http://www.soebes.de

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


Re: Maven Assemblies

Posted by David Weintraub <qa...@gmail.com>.
Thanks for your help. I kept seeing the assembly file referenced, but
nothing too much on where it should be.

Here's my Assembly file:

assembly>
    <id>bin</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <baseDirectory>${artifactId}-${version}</baseDirectory>
    <includeSiteDirectory>false</includeSiteDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
            <unpack>false</unpack>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>src/main/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <lineEnding>lf</lineEnding>
            <fileMode>0755</fileMode>
            <includes>
                <include>**</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>src/main/conf</directory>
            <outputDirectory>conf</outputDirectory>
            <lineEnding>lf</lineEnding>
            <fileMode>0644</fileMode>
            <includes>
                <include>**</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

Originally, I tried to create a src/main/instance directory, and any
files in that directory would be included in the root of the tar.gz
file. However, it kept putting them under src/main/conf/instance in
the tarball instead of in the root. I finally just defined two
separate filesets. I don't know if I need the <include>**</include>
line because this is the default, but it works.

There are two issues I am having:

1). In the tarball, the "lib" directory is owned by build/user, but
the bin and conf directory is owned by 0/0. Is there a way to set
this? I didn't see anything in the Assembly settings.

2). My boss wants to know why is the assembly file called bin.xml. I
told him because the assembly file is a "bin" type, and you name the
assembly file after the assembly type. He wants to see documentation
to this effect. Is there such documentation? I know you can call your
assembly file anything you want, but if this is the Maven standard, I
want to stick with it.

On Wed, Jan 28, 2009 at 8:47 AM, Karl Heinz Marbaise <kh...@gmx.de> wrote:
> Hi David,
>
>> I'm building a JAR file that needs to be packaged with some shell
>> scripts and some configuration files. The shell scripts will be in a
>> "bin" directory, the configuration files will be in a "conf"
>> directory, and I'd like the jar in the "lib" directory with any of the
>> dependency jars mentioned in the POM.
>>
>> I've read about Assemblies in Maven -- The Definitive Guide, but I am
>> a little confused about them. It looks like the Assembly is separate
>> from the POM. Is this true? If it is separate from the POM, where is
>> it suppose to live, and how does the POM refer to it?
>
> It's correct that's outside the pom. It lives in src/main/assembly or
> something like this...(see
> http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)
>
>>
>> I figure this is a pretty standard setup for a standalone JAR
>> application, but I haven't seen any examples of this particular setup.
>
> e.g. the following is a bin.xml assembly discriptor:
> May be you have to change the include and the exclude section a bit.
>
> <assembly>
>    <id>bin</id>
>    <formats>
>        <format>tar.gz</format>
>        <format>zip</format>
>    </formats>
>    <baseDirectory>${artifactId}-${version}</baseDirectory>
>    <includeSiteDirectory>false</includeSiteDirectory>
>    <dependencySets>
>        <dependencySet>
>            <outputDirectory>lib</outputDirectory>
>            <unpack>false</unpack>
>            <scope>runtime</scope>
>        </dependencySet>
>    </dependencySets>
>    <fileSets>
>        <fileSet>
>            <filtered>true</filtered>
>            <includes>
>                <include>supose.cmd</include>
>            </includes>
>        </fileSet>
>        <fileSet>
>            <includes>
>                <include>search-examples.txt</include>
>            </includes>
>            <excludes>
>                <exclude>*.log</exclude>
>                <exclude>bin/**</exclude>
>                <exclude>build/**</exclude>
>                <exclude>dist/**</exclude>
>                <exclude>test-output/**</exclude>
>                <exclude>**/target/**</exclude>
>            </excludes>
>        </fileSet>
>    </fileSets>
> </assembly>
>
> Within the pom you have to put the following: There you can configure where
> to put the assembly descriptors...
>
>  <plugin>
>      <groupId>org.apache.maven.plugins</groupId>
>      <artifactId>maven-assembly-plugin</artifactId>
>      <version>2.2-beta-3</version>
>      <configuration>
>        <descriptors>
>          <descriptor>src/main/assembly/bin.xml</descriptor>
>        </descriptors>
>      </configuration>
>      <executions>
>         <execution>
>           <phase>package</phase>
>           <goals>
>             <goal>single</goal>
>           </goals>
>         </execution>
>      </executions>
>  </plugin>
>
> That will bin the creation of the packages to the package phase...
>
>
> --
> SoftwareEntwicklung Beratung Schulung    Tel.: +49 (0) 2405 / 415 893
> Dipl.Ing.(FH) Karl Heinz Marbaise        ICQ#: 135949029
> Hauptstrasse 177                         USt.IdNr: DE191347579
> 52146 Würselen                           http://www.soebes.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
--
David Weintraub
qazwart@gmail.com

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


Re: Maven Assemblies

Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi David,

> I'm building a JAR file that needs to be packaged with some shell
> scripts and some configuration files. The shell scripts will be in a
> "bin" directory, the configuration files will be in a "conf"
> directory, and I'd like the jar in the "lib" directory with any of the
> dependency jars mentioned in the POM.
> 
> I've read about Assemblies in Maven -- The Definitive Guide, but I am
> a little confused about them. It looks like the Assembly is separate
> from the POM. Is this true? If it is separate from the POM, where is
> it suppose to live, and how does the POM refer to it?
It's correct that's outside the pom. It lives in src/main/assembly or 
something like this...(see 
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)

> 
> I figure this is a pretty standard setup for a standalone JAR
> application, but I haven't seen any examples of this particular setup.
e.g. the following is a bin.xml assembly discriptor:
May be you have to change the include and the exclude section a bit.

<assembly>
     <id>bin</id>
     <formats>
         <format>tar.gz</format>
         <format>zip</format>
     </formats>
     <baseDirectory>${artifactId}-${version}</baseDirectory>
     <includeSiteDirectory>false</includeSiteDirectory>
     <dependencySets>
         <dependencySet>
             <outputDirectory>lib</outputDirectory>
             <unpack>false</unpack>
             <scope>runtime</scope>
         </dependencySet>
     </dependencySets>
     <fileSets>
         <fileSet>
             <filtered>true</filtered>
             <includes>
                 <include>supose.cmd</include>
             </includes>
         </fileSet>
         <fileSet>
             <includes>
                 <include>search-examples.txt</include>
             </includes>
             <excludes>
                 <exclude>*.log</exclude>
                 <exclude>bin/**</exclude>
                 <exclude>build/**</exclude>
                 <exclude>dist/**</exclude>
                 <exclude>test-output/**</exclude>
                 <exclude>**/target/**</exclude>
             </excludes>
         </fileSet>
     </fileSets>
</assembly>

Within the pom you have to put the following: There you can configure 
where to put the assembly descriptors...

   <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-assembly-plugin</artifactId>
       <version>2.2-beta-3</version>
       <configuration>
         <descriptors>
           <descriptor>src/main/assembly/bin.xml</descriptor>
         </descriptors>
       </configuration>
       <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
       </executions>
  </plugin>

That will bin the creation of the packages to the package phase...


-- 
SoftwareEntwicklung Beratung Schulung    Tel.: +49 (0) 2405 / 415 893
Dipl.Ing.(FH) Karl Heinz Marbaise        ICQ#: 135949029
Hauptstrasse 177                         USt.IdNr: DE191347579
52146 Würselen                           http://www.soebes.de

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