I am doing a maven project. Everything is fine when compiling and running my project in an idea, but whenever I create jar file, my external jar files in web/lib/ cannot be copied into the jar file. Why this occurs ? Can I insert my all files into the jar file ?
Asked
Active
Viewed 1,473 times
3 Answers
2
You can use the jar-with-dependencies descriptor of Maven Assembly Plugin to achieve this.

Raghuram
- 51,854
- 11
- 110
- 122
1
You need to use Maven Assembly plugin something like this:
</project>
...
<build>
...
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest> <!-- requires for executable Jar -->
<mainClass>org.my.main.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef> <!-- final Jar will have this text appended -->
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- append to the packaging phase. -->
<goals>
<goal>single</goal> <!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
....
</plugins>
</build>
</project>

Nishant
- 54,584
- 13
- 112
- 127
-
I have already used this plugin. I am using Symmetricds jar files in my project, but I could not see these jar files in the jar file. Symmetricds jar files in web/lib directory. – olyanren Feb 15 '11 at 08:33
-
@Muhammed Yüce, Are these Symmetricds jar files added as dependencies in your pom.xml? – Nishant Feb 15 '11 at 08:42
-
NO, they did not. Because these jar files are special to Symmetric Ds which provides synchronization between two database. I just want to add the folder which contains jar files, into executable jar file. – olyanren Feb 15 '11 at 08:48
-
@Muhammed Yüce -- So, you need to add those Jars as dependencies. Since they are not publicly available, you need to install them in your local repo like `mvn install:install-file -Dfile=
-DgroupId= – Nishant Feb 15 '11 at 09:15-DartifactId= -Dversion= -Dpackaging=jar` and add it to dependencies list. They will be available in the package. see here http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html you can also use one-jar to manually create a jar bundle see here http://one-jar.sourceforge.net/ -
My folder is under src folder. This link shows how we can add src folder : http://stackoverflow.com/questions/4831831/maven-to-copy-jar-when-adding-dependencies – olyanren Feb 15 '11 at 09:19
0
Yes I found solution.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<finalName>HelloWorld</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.gui.launcher.LauncherMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- append to the packaging phase. -->
<goals>
<goal>single</goal>
<!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>

olyanren
- 1,448
- 4
- 24
- 42