Why am I getting this error when I try to use the Maven build plugin?

I am completely new to Maven and I am learning it in a tutorial.

In this tutorial, I have the following pom.xml config 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 config file, the use of the build plugin is declared , 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>

      

The descripor field is set to jar-with-dependencies , which (from what I understood) should create a new target jar file that also contains the delcared.jar of my project's dependencies.

So in Eclipse I select my prject and Run from ---> Maven Build and in the Target input section I write this entry:

clean package assembly:single

      

which should clear the target directory of my project, create a package and invoke the target single in the plugin build which will put the jar dependecies in my final target jar file of my project.

The problem is that in this case I get the following error in 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 can't seem to find this file: / home / andrea / git / maven-java-console-application / mvntutorial1 / jar-with-dependencies

But from what I understood in the tutorial, this is not a config file, but a Maven specific value that says to put all .jar dependencies in my final jar container file that represents my packaged project.

Why am I getting this error? What am I missing? How can I fix this?

+3


source to share


2 answers


It seems you are not using the plugin assembly

correctly. 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 perform: clean install

. This will create a jar of dependencies in the directory target

. You can refer to these examples from this link: https://maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html

+4


source


So this is how my Maven MOM looks like in relation to the plugin.

<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:

  • You either didn't format it correctly, or the version of maven you are using does not support what you want to do.
  • You may have misconfigured your bash profile and specified where the maven directory is. Also, if possible, try setting up your maven projects through the terminal command line as shown on the apache website and see if it works. There is a link: http://maven.apache.org/archetype/maven-archetype-plugin/examples/generate-batch.html


Ex: This is the command I am using to create the 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

      

GroupID creates the path (think of it as a package) and since artificatID is the name of the class.

+1


source







All Articles