我正在做一個maven項目。編譯和運行我的項目時,一切都很順利,但每當我創建jar文件時,web/lib /中的外部jar文件都不能複製到jar文件中。爲什麼會發生?我可以將所有文件插入jar文件嗎?將jar庫添加到jar文件中
2
A
回答
0
是我找到的解決方案。
<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>
2
您可以使用Maven Assembly Plugin的jar-with-dependencies描述符來實現此目的。
1
您需要使用是這樣的:
</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>
相關問題
- 1. 如何將jar庫添加到jar中
- 2. 將庫路徑添加到jar文件
- 3. 如何將jar文件添加到jar文件中?
- 4. 添加jar文件到C#類庫
- 5. 將外部庫添加到JAR中?
- 6. 將Jar文件添加到WEB-INF/lib
- 7. 將Jar文件添加到Maven
- 8. 將.dll文件添加到jar
- 9. 將.jar文件添加到React本機
- 10. 添加Jar文件
- 11. 將jar添加到eclipse插件中
- 12. 將JAR添加到Eclipse Java庫
- 13. 將jar庫添加到Maven項目
- 14. 將Volley和Gson添加到庫Jar
- 15. Android將jar添加到自定義庫
- 16. 將HttpClient jar添加到eclipse
- 17. 將庫JAR文件添加到EJB項目
- 18. 將sqlite數據庫添加到可執行的JAR文件
- 19. 如何將java類添加到jar文件中的文件夾
- 20. 將多個文件添加到Jar文件中,Python
- 21. 將外部庫添加到IntelliJ IDEA中的工件jar中
- 22. 將jar添加到eclipse插件(hadoop)
- 23. 將jar添加到Eclipse插件
- 24. Eclipse將引用的jar添加到導出的jar文件中的問題
- 25. Android - 添加JAR文件到eclipse(hotpotato API)
- 26. 將庫嵌入到jar文件
- 27. Java applet,將jar文件添加到清單文件
- 28. WildFly - 將JAR添加到類路徑中
- 29. 添加外部Jar庫
- 30. 如何將jar文件添加到構建路徑中
我已經使用過這個插件。我在我的項目中使用Symmetricds jar文件,但在jar文件中看不到這些jar文件。在web/lib目錄中對稱jar文件。 – olyanren 2011-02-15 08:33:40