adding jar libraries into jar file
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开发者_StackOverflow file ?
You can use the jar-with-dependencies descriptor of Maven Assembly Plugin to achieve this.
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>
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>
精彩评论