我是使用Java EE在Eclipse中构建动态Web项目的新手。一开始一切顺利,我可以在WebSphere Application Server for Liberty(版本16.0.0.4)上本地运行我的Web项目,并从
访问我的网页本地主机: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方面来恢复该问题,并重新添加方面重新引入了问题。根据这个link,添加一个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而不是以后,我遇到了同样的问题。我已经尝试将contextRoot =“MainApplication”添加到我的web项目下的server.xml中,这也不起作用。如果我右键单击我的项目 - &gt;属性 - &gt; Web项目设置 - &gt;上下文根: 该值设置为MainApplication。 一个stackoverflow帖子在这里有类似的问题: WebSphere Liberty Profile: Context Root Not Found 但他的修复包含了我在项目中没有的一些文件(ibm-web-ext.xml&amp; ibm-web-bnd.xml)。 Neverthless我尝试在我的WEB-INF目录中创建这些文件但仍然无效。
过去3天我一直在寻找解决方案并且无处可去,并且已经用尽了我的所有想法。任何帮助表示赞赏。
答案 0 :(得分:2)
webProfile-7.0功能引入了jsf-2.2功能,因此问题可能是由于两个jsf实现。为了确保这不是问题,您可以列出webprofile独立提供的每个功能,但删除jsf,所以: jsp-2.3,ejbLite-3.2,managedBeans-1.0,beanValidation-1.1,servlet-3.1,ssl-1.0,jndi-1.0,jsonp-1.0,appSecurity-2.0,jdbc-4.1,jaxrs-2.0,jaxrsClient-2.0,el- 3.0,json-1.0,jpaContainer-2.1,cdi-1.2,distributedMap-1.0,websocket-1.1,jpa-2.1
另外还有两项功能:adminCenter-1.0,localConnector-1.0