Why I obtain this error message when I try to use the Maven assembly plugin?

20,053

Solution 1

It seems you are not using the assembly plugin properly. Change the plugin entry to this :

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>com.test.MainClassName</mainClass>
      </manifest>
    </archive>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
  <executions>
    <execution>
      <id>make-assembly</id> 
      <phase>package</phase> <!-- packaging phase -->
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Then you just need to execute : clean install. This will create the jar with dependencies in the target directory. You can refer to these examples given at this link : https://maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html

Solution 2

So this here is how my maven POM looks like in regards to the plug in.

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target> 
                </configuration>
            </plugin>
        </plugins>
    </build>

I can only assume two things:

  1. You either did not format it properly, or the version of maven you are using doesn't support what you wish to do.
  2. You may have not properly set up your bash profile and stipulate where the maven directory is located. Also, if possible try setting up your maven projects via the terminal/command prompt as is displayed on the apache website and see if it works. Link is : http://maven.apache.org/archetype/maven-archetype-plugin/examples/generate-batch.html

Ex: This is a command I use to create a maven archetype for one of my projects:

mvn -B archetype:generate \-DarchetypeGroupId=org.apache.maven.archetypes \-DgroupId=com.weather.mobile.ios.automation.tenday \-DartifactId=IphoneTenDayAutomation

The groupID creates the pathway (think of it like the package), while as the artificatID is the name of the class.

Share:
20,053
AndreaNobili
Author by

AndreaNobili

Updated on July 09, 2022

Comments

  • AndreaNobili
    AndreaNobili almost 2 years

    I am absolutly new in Maven and I am studying it on a tutorial.

    In this tutorial I have the following pom.xml configuration file:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.denofprogramming</groupId>
        <artifactId>maventutorial1</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>MavenTutorial1</name>
        <url>http://maven.apache.org</url>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.5.5</version>
                    <configuration>
                        <descriptors>
                            <descriptor>jar-with-dependencies</descriptor>
                        </descriptors>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
        <dependencies>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-math3</artifactId>
                <version>3.2</version>
            </dependency>
    
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
    </project>
    

    As you can see in this configuration file it is declared the use of the assembly plugin, this section:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.5</version>
                <configuration>
                    <descriptors>
                        <descriptor>jar-with-dependencies</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
    

    As descripor field it is setted the value jar-with-dependencies that (from what I have understand) have to create a new target jar file that contains also the delcared .jar dependencies of my project.

    So, into Eclipse, I select my prject and the Run as ---> Maven Build and into the Goal input section I write this statment:

    clean package assembly:single
    

    that have to clean the target directory of my project, create the package and call the single goal on the assembly plugin that put the jar dependecies into my final jar target file of my project.

    The problem is that doing in this way I obtain the following error message into the Eclipse console:

    .......................................................
    .......................................................
    .......................................................
    
    Results :
    
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] 
    [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ maventutorial1 ---
    [INFO] Building jar: /home/andrea/git/maven-java-console-application/mvntutorial1/target/maventutorial1-0.0.1-SNAPSHOT.jar
    [INFO] 
    [INFO] --- maven-assembly-plugin:2.5.5:single (default-cli) @ maventutorial1 ---
    [INFO] Reading assembly descriptor: jar-with-dependencies
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.767 s
    [INFO] Finished at: 2015-07-20T15:12:19+01:00
    [INFO] Final Memory: 19M/155M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.5.5:single (default-cli) on project maventutorial1: Error reading assemblies: Error locating assembly descriptor: jar-with-dependencies
    [ERROR] 
    [ERROR] [1] [INFO] Searching for file location: /home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies
    [ERROR] 
    [ERROR] [2] [INFO] File: /home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies does not exist.
    [ERROR] 
    [ERROR] [3] [INFO] File: /home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies does not exist.
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    

    It seems that it can't find this file: /home/andrea/git/maven-java-console-application/mvntutorial1/jar-with-dependencies

    But from what I have understand on the tutorial this is not a configuration file but a specific Maven value that say to put all the .jar dependencies into my final target jar file that represent my packaged project.

    Why I obtain this error? What am I missing? How can I fix it?