我有一个在IBM Bluemix上运行的简单JSF应用程序,可以很好地处理以下J2EE依赖项。
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
用JSF依赖项替换它时
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.2</version>
</dependency>
我收到以下错误
尚未找到此请求的应用程序或上下文根目录:/
任何帮助?
我的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>Java DB Web Starter</display-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<persistence-context-ref>
<persistence-context-ref-name>openjpa-todo/entitymanager</persistence-context-ref-name>
<persistence-unit-name>openjpa-todo</persistence-unit-name>
</persistence-context-ref>
<resource-ref>
<!-- The cloudAutowiring-1.0 Liberty feature will resolve this to whatever
the database service name is -->
<!-- When running locally without this feature, create a datasource with
the JNDI name "jdbc/mydbdatasource" in server.xml -->
<!-- If using MySQL locally then use the "url" property and append "?relaxAutoCommit=true", for example:
<dataSource id='mysql-datasource' jdbcDriverRef='mysql-driver' jndiName='jdbc/mydbdatasource'>
<properties user='root' password='password' url="jdbc:mysql://localhost:3306/db?relaxAutoCommit=true"/>
</dataSource> -->
<res-ref-name>jdbc/mydbdatasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
答案 0 :(得分:1)
检查您的web.xml,您应该使用
调用您的应用程序https://[your_application_URL]/faces/
而不是
https://[your_application_URL]/
因为Faces Servlet正在根据
监听此路径<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
与jax-rs webservice根据
监听/ api路径的方式相同<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
在聊聊问题后编辑:
问题在于使用了jsf依赖项,这使得app使用包含java包com.sun.faces下的类的jsf-impl-xxx.jar,而不是使用jsf加载的包javax.faces下的类-api-xxx.jar(使用j2ee-web-api依赖时使用) 最后一个jar中的类是JSF规范定义的标准API的实现。
如果您只想为JSF添加依赖项而不使用整个j2ee-web-api,您可以使用工件 jsf-api-xxx作为依赖
它将解决您的问题
答案 1 :(得分:0)
我找到了答案Here
<强>简言之强>:
如果你正在使用Maven,你可以在下面找到必要的坐标:
Java EE容器(WildFly,JBoss,TomEE,Payara,GlassFish,WebSphere等)
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version><!-- 7.0 (JSF 2.2) or 6.0 (JSF 2.0/2.1) --></version>
<scope>provided</scope>
</dependency>
请注意,Java EE版本必须与服务器自己的Java EE版本匹配。在针对Java EE 6服务器时,您无法将其设置为7.0。
Servletcontainers(Tomcat,Jetty等)
<强>钻嘴鱼科强>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>// jsf-imp and jsf-api were been mereged into one jar
<version><!-- Check http://javaserverfaces.java.net --></version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
您还可以查看org.glassfish:javax.faces存储库,了解当前最新的Mojarra发行版本(截至目前为2.2.13)。
<强> MyFaces的强>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version><!-- Check http://myfaces.apache.org --></version>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version><!-- Check http://myfaces.apache.org --></version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>