我是使用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