2017-08-01 36 views
0

我想在我的項目中使用war文件。你認爲我可以在基於Maven的項目中做到這一點嗎?爲了做到這一點,我應該在pom.xml中編寫或定義一些東西?如何在基於maven的項目中使用戰爭

可以將一個外部jar添加到pom.xml中。但是是否可以向pom.xml添加外部戰爭並使用它的類,例如我們使用jar作爲庫?

+0

這個問題太廣泛了。提供一個示例項目(或兩個,一個用於WAR),並準確描述,您想要達到的目標以及您已經嘗試完成的項目。 –

+0

我有一個基於java的spring maven項目。我想在我的項目中使用基於java的基於spring maven的項目。我想用它的一些類。你認爲我應該在pom.xm中做些什麼嗎?我想這是很好的描述 – user2307786

+0

你可能會這樣猜測。我不這麼認爲。其他人可能並不這麼認爲。我只是試圖向你展示如何得到更好的支持。拿它或離開它:-) –

回答

3

我不知道是否有可能從技術面上看,但我會避免。相反,把你想要重用的類放到一個jar項目中,並從你所有的戰爭項目中引用這個jar。

-1
type 

元素可以用來提供依賴類型和類可以使用。

 <xs:element name="type" minOccurs="0" type="xs:string" default="jar"> 
    <xs:annotation> 
     <xs:documentation source="version">4.0.0</xs:documentation> 
     <xs:documentation source="description"> 
     The type of dependency. This defaults to jar. While it usually represents the extension on 
     the filename of the dependency, that is not always the case. A type can be mapped to a different 
     extension and a classifier. 
     The type often correspongs to the packaging used, though this is also not always the case. 
     Some examples are jar, war, ejb-client and test-jar. 
     New types can be defined by plugins that set 
     extensions to true, so this is not a complete list. 
     </xs:documentation> 
    </xs:annotation> 
    </xs:element> 

例如:

<dependency> 
     <groupId>project-group</groupId> 
     <artifactId>war-artifact</artifactId> 
     <version>1.0-SNAPSHOT</version> 
     <type>war</type> 
    </dependency> 
+0

爲什麼倒投了? – rathna

+0

因爲你沒有回答這個問題:你只是說可以引用戰爭,而不是如果可以使用這場戰爭中的類,就好像它是一個罐子一樣。 –