![](/img/trans.png)
[英]Spring with maven, jar packaging, not displaying welcome.jsp page
[英]Maven Spring jar packaging
我們創建了一個 jar(Spring 項目),我們在另一個 Spring 項目(戰爭)中使用了 Maven
如果我們包含所需的依賴項,我們可以毫無問題地使用它。
如果我想確保 jar 包含它的所有依賴項並使用它們,那么 go 的最佳方法是什么?
為了避免必須包含我在使用 maven 程序集插件時嘗試過的依賴項,該插件肯定包含文件 - 但這些似乎被忽略了,因為它們仍然需要作為消費項目中的依賴項 - 有什么建議嗎?
組裝插件的 POM 詳細信息
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
您可以使用 maven winstone 插件創建一個獨立的可執行文件 jar,其中包含戰爭中的所有依賴項,jar 等...
添加
<plugins>
<plugin>
<groupId>net.sf.alchim</groupId>
<artifactId>winstone-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>embed</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
<configuration>
<filename>${project.parent.build.finalName}.jar</filename>
</configuration>
</plugin>
...
</plugins>
將捆綁您應用程序的所有模塊、wars 和 jars,以及包含 servlet 引擎的可執行 jar 中的任何所需依賴項。
這非常適合為您的 Ops 團隊提供一個可部署的捆綁包進行部署。
但是,我建議不要創建 jar ,其中包含戰爭要使用的所有依賴項。 您可能會在 class 路徑中獲得相同類的略有不同版本的多個副本。 某些庫有點euhhmmm,...,關於這個的氣質(休眠和log4j spring)。
Maven 在確定要采用哪些依賴項方面做得不錯,如果事情破壞了mvn dependency:tree讓事情變得更加清晰。 當你創建一個 uber-jar 時,你會丟失這個。
如果有充分的理由這樣做,我會推薦一個可以嚴格控制類路徑的環境,例如成熟的 J2EE 服務器或使用 OSGi 容器。 但是,要小心你想要的:這些不是沒有(鐵)手套就可以處理的小貓。
我使用以下程序集配置來創建 jar,其中包含所有運行時依賴項:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>runnable</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.