Omnifaces library in JSF, Java classpath Cannot find type
Asked Answered
G

1

3

I try to recover the constants in my xhtml jsf in using Omnifaces library, but when I run my project I get:

Cannot find type 'fr.epsi.utils.ConstantsPages' in classpath.

Here is my xhtml page :

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:o="http://omnifaces.org/ui">
<o:importConstants type="fr.epsi.utils.ConstantsPages" />
<h:head>
    <title>Acceuil</title>
    <h:outputStylesheet name="css/style.css"/>
</h:head>
<h:body>
    <h:panelGrid columns="3" cellpadding="10">
        <h:link value="Home" outcome="#{ConstantsPages.LOGIN_PAGE}" />
    </h:panelGrid>
<h:body>
</html>

And my ConstantsPages class :

package fr.epsi.utils;

public class ConstantsPages {    
    /* GENERAL */
    public static final String LOGIN_PAGE = "/General/login";
    public static final String LOGIN_CLIENT_PAGE = "/General/loginClient";
    public static final String LOGIN_TECHNICIEN_PAGE = "/General/loginTechnicien";
    public static final String ACCUEIL_PAGE = "/General/accueil";
}

And the stack trace :

java.lang.IllegalArgumentException: Cannot find type 'fr.epsi.utils.ConstantsPages' in classpath.
at org.omnifaces.taghandler.ImportConstants.toClass(ImportConstants.java:173)
at org.omnifaces.taghandler.ImportConstants.collectConstants(ImportConstants.java:134)
at org.omnifaces.taghandler.ImportConstants.apply(ImportConstants.java:117)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: fr.epsi.utils.ConstantsPages
at com.sun.enterprise.loader.ASURLClassLoader.findClassData(ASURLClassLoader.java:808)
at com.sun.enterprise.loader.ASURLClassLoader.findClass(ASURLClassLoader.java:696)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.omnifaces.taghandler.ImportConstants.toClass(ImportConstants.java:156)
... 36 more

Please help me!

Gutter answered 11/6, 2013 at 19:32 Comment(0)
G
2

You need to make sure that the class file is properly compiled and placed in webapp's runtime classpath. E.g. as /WEB-INF/classes/fr/epsi/utils/ConstantsPages.class inside the WAR.

This exception says that it is not. There's really no other cause. If you're using an IDE, make sure that the class file is inside Java source folder of the web project and that you've cleaned, rebuilt and redeployed the project and restarted the server.

Griff answered 20/6, 2013 at 13:17 Comment(10)
I have mine in a jar, would that be okay?Bluebird
I am working with maven. It is in the /WEB-INF/classes/de...... They are also inside the Java source folder of the web project. Is there any difference?Rudolf
@Alexander: and OmniFaces is in WAR's /WEB-INF/lib? I could imagine that it may fail when OmniFaces is incorrectly placed in EAR's /lib.Griff
omnifaces-2.0.jar is in the lib folder of the war, yes (/WEB-INF/lib/omnifaces-2.0.jar). Other components such as {now} are working.Rudolf
@Alexander: which appserver? Are you inside a test managed bean able to perform Class#forName() on that class with Thread.currentThread().getContextClassLoader()?Griff
WildFly 8.2. As alternate approach: Can I follow this one: #4707226 ?Rudolf
@Griff Yes - it is working perfectly (Sorry, missed your edit I guess).Rudolf
@Alexander: OK this is weird. Is it a default WildFly or with a modified standalone.xml? I've never seen this before on our own WildFly setups.Griff
Let us continue this discussion in chat.Rudolf
@Griff Did you found any solution here?Rudolf

© 2022 - 2024 — McMap. All rights reserved.