0

I'm trying to create a project with Mojarra 2.3.8 and PrimeFaces 8.0 for Tomcat 8 Application server. I used IntelliJ for building and testing my web application.

Following WELD installation instruction I installed all dependencies using maven, my pom file is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>SensorWebHub3</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <!-- dependencies for PrimeFaces -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
        </dependency>

        <dependency>
            <groupId>com.lowagie</groupId>
            <artifactId>itext</artifactId>
            <version>2.1.7</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
            <artifactId>owasp-java-html-sanitizer</artifactId>
            <version>20190503.1</version>
        </dependency>
       <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>8.0</version>
        </dependency>

        <!-- dependencies for CDI WELD -->
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-shaded</artifactId>
            <version>3.1.4.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.1.2.Final</version>
        </dependency>

        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jandex</artifactId>
            <version>2.1.3.Final</version>
        </dependency>

    </dependencies>

</project>

I created the context.xml file in META-INF directory:

<Context>
    <Resource name="BeanManager"
              auth="Container"
              type="javax.enterprise.inject.spi.BeanManager"
              factory="org.jboss.weld.resources.ManagerObjectFactory" />

</Context>

I create an empty beans.xml file putted into WEB-INF directory; moreover I created the web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">


    <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>


    <context-param>
        <param-name>primefaces.FONT_AWESOME</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.LEGACY_WIDGET_NAMESPACE</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>nova-light</param-value>
    </context-param>
</web-app>

my simple index.xhtml file is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
   <f:view>
      <h:outputLabel value="Hello, world"/>
      <p:textEditor />
   </f:view>
</html>

and my project structure is: enter image description here

I configured IntelliJ IDEA in order to run Tomcat 8.5.54 Application server. When I run tomcat, it tries to deploy the war file but I get the following exception:

/Users/lerocchi/Tomcat-8.5.54/bin/catalina.sh run
[2020-04-15 06:10:22,449] Artifact swh3: Waiting for server connection to start artifact deployment...
15-Apr-2020 18:10:23.000 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/8.5.54
15-Apr-2020 18:10:23.001 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Apr 3 2020 14:06:10 UTC
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 8.5.54.0
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Mac OS X
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.15.4
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          x86_64
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_45-b14
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /Users/lerocchi/Tomcat-8.5.54
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3/conf/logging.properties
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=/Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3/jmxremote.password
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=/Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3/jmxremote.access
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
15-Apr-2020 18:10:23.004 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3
15-Apr-2020 18:10:23.004 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/Users/lerocchi/Tomcat-8.5.54
15-Apr-2020 18:10:23.004 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/Users/lerocchi/Tomcat-8.5.54/temp
15-Apr-2020 18:10:23.004 INFORMAZIONI [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/lerocchi/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
15-Apr-2020 18:10:23.104 INFORMAZIONI [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
15-Apr-2020 18:10:23.120 INFORMAZIONI [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
15-Apr-2020 18:10:23.131 INFORMAZIONI [main] org.apache.catalina.startup.Catalina.load Initialization processed in 422 ms
15-Apr-2020 18:10:23.156 INFORMAZIONI [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
15-Apr-2020 18:10:23.156 INFORMAZIONI [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.54
15-Apr-2020 18:10:23.163 INFORMAZIONI [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
15-Apr-2020 18:10:23.170 INFORMAZIONI [main] org.apache.catalina.startup.Catalina.start Server startup in 38 ms
Connected to server
[2020-04-15 06:10:23,540] Artifact swh3: Artifact is being deployed, please wait...
15-Apr-2020 18:10:23.956 AVVERTENZA [RMI TCP Connection(2)-127.0.0.1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
15-Apr-2020 18:10:25.895 INFORMAZIONI [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
15-Apr-2020 18:10:25.931 INFO [RMI TCP Connection(2)-127.0.0.1] org.jboss.weld.environment.servlet.EnhancedListener.onStartup WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
15-Apr-2020 18:10:25.952 INFO [RMI TCP Connection(2)-127.0.0.1] org.jboss.weld.bootstrap.WeldStartup.<clinit> WELD-000900: 3.1.4 (Final)
15-Apr-2020 18:10:26.030 INFO [RMI TCP Connection(2)-127.0.0.1] org.jboss.weld.environment.deployment.discovery.DiscoveryStrategyFactory.create WELD-ENV-000020: Using jandex for bean discovery
15-Apr-2020 18:10:26.080 WARN [RMI TCP Connection(2)-127.0.0.1] org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize WELD-ENV-000028: Weld initialization skipped - no bean archive found
15-Apr-2020 18:10:26.122 INFORMAZIONI [RMI TCP Connection(2)-127.0.0.1] com.sun.faces.config.ConfigureListener.contextInitialized Initializing Mojarra 2.3.8 ( 20181116-0037 55af8b79ca53ec2df566f9c08a430259d30f9ba5) for context '/swh3'
15-Apr-2020 18:10:26.293 INFORMAZIONI [RMI TCP Connection(2)-127.0.0.1] com.sun.faces.spi.InjectionProviderFactory.createInstance JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
15-Apr-2020 18:10:26.434 GRAVE [RMI TCP Connection(2)-127.0.0.1] com.sun.faces.config.ConfigureListener.contextInitialized Critical error during deployment: 
    com.sun.faces.config.ConfigurationException: Factory 'javax.faces.lifecycle.ClientWindowFactory' was not configured properly.
        at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:357)
        at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:243)
        at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:443)
        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:237)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4699)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
        at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1720)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
       ...
       ...

I have no idea...

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
N3tMaster
  • 398
  • 3
  • 13
  • 1
    Do you really need that jsf jar? Try also to look at [this](https://stackoverflow.com/questions/31033946/java-lang-illegalargumentexception-javax-faces-lifecycle-clientwindowfactory). – WoAiNii Apr 15 '20 at 18:27
  • Thank you for your suggestion, I remove the mojarra 2.3.8 jar from my war and now It is able to be deploy in my Tomcat8 without any problem. But now I can't reach the initial page: browser says "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." – N3tMaster Apr 16 '20 at 10:41
  • 1
    Removing the jar from the war does not solve the problem. You **NEED** this jar in a war that is going to be deployed in the tomcat since tomcat by default does not contain jsf. With removing this, you create new problems, sure since e.g. .xhtml files are not mapped anymore and then you get these new errors... , yes new, but it would be the same like not deploying your app at all and then trying to access a pages. You'll get 404's then, but the original error will be gone... – Kukeltje Apr 16 '20 at 11:02
  • @WoAiNii: The post you refer to is about mixing two different (versions of) JSF implementations. Does not seem to be the case here, so it is not related. – Kukeltje Apr 16 '20 at 11:04
  • @Kukeltje: My fault, didn't know Tomcat didn't provide jsf impl, I see jboss in the stack trace and I think there could be already another jar. So what's the problem, [Weld](https://docs.jboss.org/weld/reference/latest/en-US/html/environments.html#_tomcat) isn't compatible with Tomcat8? Missing others configuration? – WoAiNii Apr 16 '20 at 14:41
  • @WoAiNii : I resolve the problem moving context.xml into META-INF directory – N3tMaster Apr 16 '20 at 15:02
  • 1
    @N3tMaster: Where did you find this solution? Please post the link so we can mark as a duplicate. And using a real Java-EE server if you are intending to use cdi, jsf etc is a waaaay better solution. Less integration issues like these. Cheers! – Kukeltje Apr 16 '20 at 15:20
  • Btw, I rolled back your edits, these types of edits don't belong in questions – Kukeltje Apr 16 '20 at 15:31
  • @Kukeltje I find the solution myself... just following my intuition.. and it works like a charme :-) . Yes I known i should use a real JavaEE (as TomEE) but I can't, I have to work with an Ubuntu server with installed Tomcat8... Cheers – N3tMaster Apr 16 '20 at 15:39
  • 1
    The ones that made the choice to force this: _" I have to work with an Ubuntu server with installed Tomcat8."_ should be fired... It's easy to add a custom repository for your ubuntu servers (we do it too, but for wildfly) and deploy the server from there and do not make you limited to what ubuntu provides.... bad, bad, bad choice. Let them read this comment ;-) – Kukeltje Apr 16 '20 at 16:02
  • 1
    Oh and if your found the answer, create an answer to your own question... Cheers – Kukeltje Apr 16 '20 at 16:06
  • @Kukeltje eh you are right but the server with Tomcat8 is used for a lot of services in production.... anyway you're right ;-). – N3tMaster Apr 16 '20 at 16:06
  • @Kukeltje: I found another solution: I tried with OpenWebBeans, following the official instructions but I had to put context.xml into the META-INF directory in order to make it run – N3tMaster Apr 16 '20 at 16:09
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/211820/discussion-between-kukeltje-and-n3tmaster). – Kukeltje Apr 16 '20 at 17:17

2 Answers2

0

In web.xml added the listener for beans configurations:

<listener>
    <listener-class>`org.jboss.weld.environment.servlet.Listener`</listener-class>
</listener>

And delete the following:

<listener> 
    <listenerclass>
        org.apache.webbeans.servlet.WebBeansConfigurationListener
    </listener-class>
</listener>
-1

After several attempts, I found this solution:

I adopt OpenWebBeans instead the WELD solution:

I put the dependencies in my new pom.xml:

<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>2.0.SP1</version>
</dependency>
<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-atinject_1.0_spec</artifactId>
    <version>1.0</version>
</dependency>

<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-jcdi_2.0_spec</artifactId>
    <version>1.0.1</version>
</dependency>

<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-interceptor_1.2_spec</artifactId>
    <version>1.0</version>
</dependency>

<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-annotation_1.3_spec</artifactId>
    <version>1.0</version>
</dependency>

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-spi</artifactId>
    <version>2.0.16</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-impl</artifactId>
    <version>2.0.16</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-web</artifactId>
    <version>2.0.16</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-jsf</artifactId>
    <version>2.0.16</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-el22</artifactId>
    <version>2.0.16</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-tomcat7</artifactId>
    <version>2.0.16</version>
    <scope>compile</scope>
</dependency>

In web.xml I added the listener for beans configurations:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <listener>
        <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</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>

I changed the faces version into faces-config.xml:

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
    http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd">

</faces-config>

The new context.xml file is moved into META-INF directory

<Context>
    <Resource name="BeanManager"
              auth="Container"
              type="javax.enterprise.inject.spi.BeanManager"
              factory="org.apache.webbeans.container.ManagerObjectFactory" />
</Context>

The new project structure is:

enter image description here

And now it works on Tomcat 8 server.

N3tMaster
  • 398
  • 3
  • 13
  • 2
    this answer is sort of not good. Your question is about weld, the answer is about using OWB. Not that OWB is not good, but in the context of your question, the answer is bad. – Kukeltje Apr 16 '20 at 17:16
  • yes, I see. sorry but It was my previous solution I found.. anyway I agree with you: this solution is out of the context. – N3tMaster Dec 31 '21 at 11:35