2013-07-16 37 views
1

在我目前的pom.xml中的狀態,我有的Tomcat 7 Maven插件多個上下文

<plugin> 
    <groupId>org.apache.tomcat.maven</groupId> 
    <artifactId>tomcat7-maven-plugin</artifactId> 
    <version>2.0</version> 
    <configuration> 
    <path>/myPath</path> 
    </configuration> 
</plugin> 

這是工作的罰款。我現在正在嘗試爲服務器上的圖像添加額外的上下文,以便「舊」上下文/myPath指向web應用程序,並且/images可用於解決圖像問題。
我試圖添加一個上下文文件,但是當我這樣做時,只有我的/images上下文被加載。
另外,我不想每次構建WAR(如果我在兩個上下文中使用兩個context.xml文件,情況會如此)

是否可以添加a)上下文,因爲它是可能的(使用tomcat7開發的當前狀態:運行AND b)僅指向本地文件夾的第二個上下文/圖像? 又如何?

+0

[在這裏回答](http://stackoverflow.com/a/10059792/978502) – yair

回答

2

雖然這是 answered here,認爲這將是很好的發佈XML應該如何看起來像:

<plugin> 
    <groupId>org.apache.tomcat.maven</groupId> 
    <artifactId>tomcat7-maven-plugin</artifactId> 
    <version>2.0</version> 
    <configuration> 
    <path>/myPath</path> 
    <staticContextPath>/images</staticContextPath> 
    </configuration> 
</plugin> 

對方回答使用 staticContextDocbase代替 staticContextPath,我不能分辨出兩者之間的區別,但其中一個應該工作。有沒有嘗試過自己,雖然;)


這兩個屬性的Tomcat的文檔:

staticContextDocbase:

靜態上下文文檔根基地完全合格的路徑

staticContextPath:

靜態上下文

可能是 fully qualified path是相反的相對路徑。


嗯,我鑽研了一下到插件和Apache的代碼,發現你需要staticContextDocbasestaticContextPath

staticContextDocbase是Tomcat檢索靜態上下文的路徑。在你的情況下,它是C:/images

staticContextPathhttp://<hostname>:<port>之後的URL中的部分,應將靜態上下文發送給客戶端。在你的情況下,它是/images

Maven的應配置像這樣:

<plugin> 
    <groupId>org.apache.tomcat.maven</groupId> 
    <artifactId>tomcat7-maven-plugin</artifactId> 
    <version>2.0</version> 
    <configuration> 
    <path>/myPath</path> 
    <staticContextPath>/images</staticContextPath> 
    <staticContextDocbase>C:/images</staticContextDocbase> 
    </configuration> 
</plugin> 

另注:

As seen here,插件使用Tomcat.addContext(String contextPath, String baseDir)staticContextPath作爲contextPath傳遞和staticContextDocbase作爲baseDir通過。 baseDir的文檔聲明它爲Must exist, relative to the server home

OTOH,即baseDir按原樣移動到Context.setBaseDir(String docBase)。關於的文檔的方法爲baseDir指出This can be an absolute pathname, a relative pathname, or a URL.

然後嘗試完整路徑。如果它不起作用去親戚;)。

+0

那麼我該如何將本地文件夾鏈接到靜態路徑呢? –

+0

@MatthiasG你叫什麼「本地文件夾」? – yair

+0

我想我的上下文(/ myPath)指向web應用程序即時開發和本地主機:8080 /圖像指向即ie C:\ data \ images –

相關問題