Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1007441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:37:07+00:00 2026-05-16T08:37:07+00:00

I’m starting to work with Maven but am not yet successfully thinking in Maven’s

  • 0

I’m starting to work with Maven but am not yet successfully thinking in Maven’s terms. I have a specific requirement and the docs aren’t giving me enough clues, so I could use a bit of help:

I’d like to create an assembly that

  1. builds a jar-with-dependencies like the “standard” target of this name, but excluding a couple of the resources. I want log4j.properties and a couple of other configuration files to not be in the jar.

  2. builds a .ZIP file containing in its root directory the .jar from step 1 as well as the above mentioned config files.

I want to fire this assembly up from the command line (only), hence no need to tie to a phase (or goal? mojo?). Preferrably using either assembly:assembly or assembly:single.

  • Do I need a custom assembly descriptor for this?
  • And is it true I can’t nest it in the pom.xml? So it goes in src/assembly/something.xml and gets referenced with a descriptorRef?
  • Can I code this as two relatively simple assemblies, of which one builds on the other (i.e. the .Zip assembly uses the .Jar assembly) or do I have to do everything in one assembly?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:37:07+00:00Added an answer on May 16, 2026 at 8:37 am

    I’m starting to work with Maven but am not yet successfully thinking in Maven’s terms.

    Welcome on board, Carl! πŸ˜€

    I want to fire this assembly up from the command line (only), hence no need to tie to a phase (or goal? mojo?). Preferrably using either assembly:assembly or assembly:single.

    Just to clarify: the build lifecycle itself is made of phases (compile, test, package, etc) and plugin goals (technically Mojos) are bound on phases. You then either invoke a phase… or just a specific plugin goal.

    Do I need a custom assembly descriptor for this?

    Well, since you want behavior that the pre-defined descriptors don’t cover, yes. You’ll even need two of them (of for the uberjar, one for the zip).

    And is it true I can’t nest it in the pom.xml? So it goes in src/assembly/something.xml and gets referenced with a descriptorRef?

    Yes, that’s true (descriptors use a custom format) and they usually go into src/main/assembly. And no, descriptorRef is for the built-in descriptors, you’ll have to use descriptor here.

    Can I code this as two relatively simple assemblies, of which one builds on the other (i.e. the .Zip assembly uses the .Jar assembly) or do I have to do everything in one assembly?

    As hinted, you’ll need two assembly descriptors. Let me help a bit…

    Let’s assume you have the following project structure:

    $ tree .
    .
    β”œβ”€β”€ pom.xml
    └── src
        β”œβ”€β”€ main
        β”‚Β Β  β”œβ”€β”€ assembly
        β”‚Β Β  β”‚Β Β  β”œβ”€β”€ jar.xml
        β”‚Β Β  β”‚Β Β  └── zip.xml
        β”‚Β Β  β”œβ”€β”€ java
        β”‚Β Β  β”‚Β Β  └── com
        β”‚Β Β  β”‚Β Β      └── stackoverflow
        β”‚Β Β  β”‚Β Β          └── App.java
        β”‚Β Β  └── resources
        β”‚Β Β      └── log4j.properties
        └── test
            └── java
                └── com
                    └── stackoverflow
                        └── AppTest.java
    

    Where the pom.xml contains the following configuration for the assembly plugin:

    <project>
      ...
      <dependencies>
        ...
      </dependencies>
      ...
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version>
            <configuration>
              <descriptors>
                <descriptor>src/main/assembly/jar.xml</descriptor>
                <descriptor>src/main/assembly/zip.xml</descriptor>
              </descriptors>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    

    The descriptor for the “filtered” uberjar (jar.xml) looks like this:

    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
      <id>uberjar</id>
      <formats>
        <format>jar</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <dependencySets>
        <dependencySet>
          <unpack>true</unpack>
          <scope>runtime</scope>
          <useProjectArtifact>false</useProjectArtifact>
        </dependencySet>
      </dependencySets>
      <fileSets>
        <fileSet>
          <directory>${project.build.outputDirectory}</directory>
          <outputDirectory>/</outputDirectory>
          <excludes>
            <exclude>log4j.properties</exclude>
          </excludes>
        </fileSet>
      </fileSets>
    </assembly>
    

    What this descriptor does is (in short):

    • include the dependencies, unpack them, but exclude the project itself (yes, this is counter intuitive but this weird default behavior has been kept for backward compatibility)
    • include the project files but exclude some of them.

    And the descriptor for the zip (zip.xml) looks like this:

    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
      <id>bin</id>
      <formats>
        <format>zip</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <fileSets>
        <fileSet>
          <directory>${project.basedir}/src/main/resources</directory>
          <outputDirectory/>
          <includes>
            <include>log4j.properties</include>
          </includes>
        </fileSet>
        <fileSet>
          <directory>${project.build.directory}</directory>
          <outputDirectory/>
          <includes>
            <include>*-uberjar.jar</include>
          </includes>
        </fileSet>
      </fileSets>
    </assembly>
    

    Which is (somehow) self explaining πŸ™‚

    • it includes the configuration files (relatively to <directory>) at the root of the assembly
    • it includes the uberjar (relatively to <directory>) at the root of the assembly

    Finally, just run mvn assembly:assembly (that’s the goal intended to be used on the CLI).


    I didn’t (knowingly) include META-INF/maven/** in the assembly for the uberjar. Is there a simple way to prevent inclusion of these?

    These are coming from the libraries that are unpacked. You can exclude them using unpackOptions. Here is a modified version of the jar.xml:

    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
      <id>uberjar</id>
      <formats>
        <format>jar</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <dependencySets>
        <dependencySet>
          <unpack>true</unpack>
          <scope>runtime</scope>
          <unpackOptions>
            <excludes>
              <exclude>META-INF/maven/**</exclude>
            </excludes>
          </unpackOptions>
          <useProjectArtifact>false</useProjectArtifact>
        </dependencySet>
      </dependencySets>
      <fileSets>
        <fileSet>
          <directory>${project.build.outputDirectory}</directory>
          <outputDirectory>/</outputDirectory>
          <excludes>
            <exclude>log4j.properties</exclude>
          </excludes>
        </fileSet>
      </fileSets>
    </assembly>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.