我是使用Java EE在Eclipse中構建動態Web項目的新起步者。起初一切都很順利,我可以我的WebSphere Application Server上本地運行我的web項目自由(版本16.0.0.4)和WebSphere Application Server for Liberty未找到上下文根
訪問我的網頁本地主機:9080/MainApplication
和在IBM BlueMix上推送到我的遠程服務器,並且所有內容也都能正常工作。
在開發過程中,我發現了JavaServer Faces功能。所以我在eclipse中進入了我的項目,並使用Mojara 2.2 JSF實現庫添加了JSF方面。只要我將JSF方面添加到我的項目中,每當我嘗試在本地運行我的Web應用程序時,都會遇到「找不到上下文根」錯誤頁面。即使試圖直接訪問我的網頁(localhost:9080/MainApplication/index.html)也會導致相同的錯誤。然而,推送到我的遠程服務器仍然正常工作,我的Web項目通常運行JSF,所以這使我相信我的本地計算機上的WebSphere Application Server配置有問題。
通過在Eclipse中從我的應用程序中刪除JSF方面來還原可修復問題,並重新添加方面會重新引入問題。根據這個,添加一個JSF構面只會將您選擇的JSF實現庫導入到項目中,添加一個「Faces配置文件」並使用faces servlet配置更新您的web.xml。所以我不明白爲什麼添加JSF方面會導致服務器找不到上下文根。 這裏是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>MainApplication</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<description>
State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
和server.xml中:
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>webProfile-7.0</feature>
<feature>localConnector-1.0</feature>
<feature>adminCenter-1.0</feature>
</featureManager>
<basicRegistry id="basic">
<user name="admin" password="adminpwd"/>
</basicRegistry>
<administrator-role>
<user>admin</user>
</administrator-role>
<remoteFileAccess>
<writeDir>${server.config.dir}</writeDir>
</remoteFileAccess>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<keyStore id="defaultKeyStore" password="adminpwd"/>
<webApplication id="MainApplication" location="MainApplication.war" name="MainApplication" contextRoot="MainApplication" type=""/>
</server>
我試圖啓動一個新項目,並從頭開始,而不是後來加入JSF和我有同樣的問題。我已經嘗試在我的web項目下向我的server.xml添加contextRoot =「MainApplication」,這也不起作用。如果我右鍵單擊我的項目 - >屬性 - > Web項目設置 - >上下文根: 該值設置爲MainApplication。 一個stackoverflow帖子在這裏有類似的問題: WebSphere Liberty Profile: Context Root Not Found 但他的修復涉及我沒有在我的項目中的一些文件(ibm-web-ext.xml ibm-web-bnd.xml)。 Neverthless我試圖在我的WEB-INF目錄中創建這些文件,但仍然無法正常工作。
我已經花了3天的時間尋找解決方案,並沒有得到任何地方,並用盡了我所有的想法。任何幫助表示讚賞。
怎麼樣,如果你從server.xml中刪除web應用和移動戰爭進入的dropins目錄? – Pete