【发布时间】:2017-07-31 05:28:46
【问题描述】:
我是使用 Java EE 在 Eclipse 中构建动态 Web 项目的新手。起初一切顺利,我可以在我的 WebSphere Application Server for Liberty(版本 16.0.0.4)上本地运行我的 Web 项目,并从
访问我的网页localhost:9080/MainApplication
然后推送到我在 IBM BlueMix 上的远程服务器,一切仍然正常。
在开发过程中,我发现了 JavaServer Faces 功能。所以我在 Eclipse 中进入了我的项目,并使用 Mojara 2.2 JSF 实现库添加了 JSF 方面。一旦我将 JSF facet 添加到我的项目中,每次我尝试在本地运行我的 Web 应用程序时,都会遇到“找不到上下文根”错误页面。即使尝试直接访问我的网页(localhost:9080/MainApplication/index.html)也会导致同样的错误。但是推送到我的远程服务器仍然有效,并且我的 Web 项目正常运行 JSF,所以这让我相信我的本地机器上的 WebSphere Application Server 配置有问题。
通过在 Eclipse 中从我的应用程序中删除 JSF facet 来恢复可以解决问题,而重新添加 facet 会重新引入问题。根据link,添加 JSF facet 只会将您选择的 JSF 实现库导入到项目中,添加“Faces 配置文件”并使用 faces servlet 配置更新您的 web.xml。所以我不明白为什么添加 JSF facet 会导致服务器找不到上下文根。 这是我的 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,但我遇到了同样的问题。我尝试将 contextRoot=”MainApplication” 添加到我的 web 项目下的 server.xml 中,但这也不起作用。如果我右键单击我的项目 -> 属性 -> Web 项目设置 -> 上下文根: 该值设置为 MainApplication。 一篇stackoverflow帖子在这里有类似的问题: WebSphere Liberty Profile: Context Root Not Found 但他的修复涉及到我的项目中没有的一些文件(ibm-web-ext.xml 和 ibm-web-bnd.xml)。尽管如此,我尝试在我的 WEB-INF 目录中创建这些文件,但仍然无法正常工作。
过去 3 天我一直在寻找解决方案,但一无所获,并用尽了我所有的想法。任何帮助表示赞赏。
【问题讨论】:
-
如果你从你的 server.xml 中删除 web 应用程序并将战争移动到 dropins 目录中呢?
标签: java eclipse jsf websphere-liberty