-1

I have an maven eclipse project which I want to export as an executable jar file from command line. I have external library jars also in the project. How can I get the executable jar file inclusive of all library jars from command line?

EDIT:: Now there is a challenge.There are actually two projects.One is PROJECT and other is Project_Framework. Both these folders are having pom.xml.The dependencies are written in pom.xml in PROJECT folder. PROJECT is dependen t on Project_Framework. After adding maven-shade plugin it is saying it cannot find the snapshot dependency of Project_Framework. How can I solve this?

Nevin Raj Victor
  • 2,924
  • 3
  • 23
  • 37
  • possible duplicate of [How can I create an executable jar with dependencies using Maven?](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven) – Alessandro Da Rugna May 08 '15 at 07:53
  • @AlessandroDaRugna: There is a challenge for me in this question.There are actually two projects.One is `PROJECT` and other is `Project_Framework`. Both these folders are having pom.xml.The dependencies are written in pom.xml in PROJECT folder. Where should I add the plugin? This is indeed confusing for me. – Nevin Raj Victor May 08 '15 at 09:15

1 Answers1

2

You have to use the maven-shade-plugin to add all dependecies to your jar.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <finalName>${project.build.finalName}</finalName>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.handlers</resource>
                    </transformer>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.schemas</resource>
                    </transformer>
                </transformers>
            </configuration>
        </plugin>

Then Change directory to PROJECT_FRAMEWORK.Then type

mvn install

Then, again change directory to PROJECT. If you have added it, you can simply run

mvn package.

Nevin Raj Victor
  • 2,924
  • 3
  • 23
  • 37
Jens
  • 67,715
  • 15
  • 98
  • 113