Wildfly 10 can't find my jar resources - wildfly

i have a project that works very well in IntelliJ + WildFly 10. I have a WAR file that uses a JAR file, this jar file contains XHTML composite components.
When i put this WAR file inside deployments folder in WildFly 10 and try to start with standalone.bat i got the following error:
Caused by: javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: //D:/jee-ronaldo/wildfly-10.1.0.Final/bin/content/easyrec-adm.war/WEB-INF/lib/myjar-web-1.0.jar/META-INF/resources/myjar/listPage.xhtml #49,93 action="#{cc.attrs.managedBean.goTo(cc.attrs.targetPage,'action','ADD')}": Target Unreachable, 'null' returned null
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:94)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 50 more
I discovery that all beans inside my WAR file are not managed by CDI. I have a beans.xml file inside WEB-INF folder but i believe that CDI didn't work.

Related

War deployment failing on Jboss 7.4

I am migrating from Jboss 6.4 to Jboss 7.4, First I have not made any changes in war file and tried to deploy it on Jboss 7.4, but I was getting below error. This error is coming for all filter and servlet classes which are configured in web.xml file.
Caused by: java.lang.IllegalArgumentException: UT010011: Filter log4jServletFilter of type class org.apache.logging.log4j.web.Log4jServletFilter does not implement javax.servlet.Filter
at io.undertow.servlet.api.FilterInfo.<init>(FilterInfo.java:74)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.createServletConfig(UndertowDeploymentInfoService.java:801)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.start(UndertowDeploymentInfoService.java:276)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
... 6 more
Then I tried with excluding undertow subsystem in jboss-deployment-structure.xml file as below. This time I was able to deploy war file without error, but application is not accessible with root context or any different way. On jboss admin console War is showing in active state but still accessible.
<exclude-subsystems>
<subsystem name="undertow" />
</exclude-subsystems>
Could anyone advise me to resolve filter or servlet class error?

How do I get an EAR to read a properties file from a WAR?

I'm using Wildfly 11 and Java 8. I'm trying to deploy an EAR file that contains multiple WAR files. One of my WAR files contains this in its web.xml ...
<context-param>
<param-name>Owasp.CsrfGuard.Config</param-name>
<param-value>csrfguard.properties</param-value>
</context-param>
The file in question is within one of my WARs at
myapp.war/WEB-INF/classes/csrfguard.properties
When I deploy the WAR by itself, everything deploys fine. However when I deploy the EAR containing the WAR I get an error complaining about not being able to locate the properties file ...
Caused by: java.io.IOException: unable to locate resource - csrfguard.properties
at org.owasp.csrfguard.CsrfGuardServletContextListener.getResourceStream(CsrfGuardServletContextListener.java:85)
at org.owasp.csrfguard.CsrfGuardServletContextListener.contextInitialized(CsrfGuardServletContextListener.java:36)
... 10 more
I sense that there is a class loader issue happening that I'm not figuring out how to work-around. How do I tell my EAR file where to find the properties file in question?
I suspect that the wrong class loader is being used to search the classpath for csrfguard.properties, which would cause getResourceAsStream to fail. In the .ear file, where does the CSRFGuard library get packaged?
You can try using the context.getRealPath fallback by switching to a path relative to the .war file:
<context-param>
<param-name>Owasp.CsrfGuard.Config</param-name>
<param-value>WEB-INF/classes/csrfguard.properties</param-value>
</context-param>
I had the same problem. Fixed it by adding the csrfguard.jar inside the WEB-INF/lib directory of the WAR file and not the lib directory of the EAR. Added the csrfguard.properties file to WEB-INF/classes directory and used the following context param in the web.xml
<context-param>
<param-name>Owasp.CsrfGuard.Config</param-name>
<param-value>csrfguard.properties</param-value>
</context-param>

Unable to build EntityManagerFactory Mapping XML JPA

Every time I configure orm.xml in the Persistance.xml I get the following:
E CWWJP0015E: An error occurred in the org.hibernate.ejb.HibernatePersistence persistence provider when it attempted to create the container entity manager factory for the XYZ persistence unit. The following error occurred: PersistenceUnit: XYZ Unable to build EntityManagerFactory
If I remove the entry from Persistance.xml it works fine, but the `Entity Manager is not able to locate the entity class since I am not using JPA annotation.
Rename Persistance.xml to persistence.xml
Note that the p is lower case and that the word 'persistence' does not contain the letter a.
Also, be sure persistence.xml is in an appropriate location:
The following is from the JPA spec:
A persistence.xml file defines a persistence unit. The persistence.xml file is
located in the META-INF directory of the root of the persistence unit.
The root of the persistence unit is the key here.
If you are a non-Java EE app
The jar file or directory whose META-INF directory contains the persistence.xml
file is termed the root of the persistence unit.
If you are in a Java EE app, the following are valid
In Java EE environments, the root of a persistence unit must be one of the following:
• an EJB-JAR file
• the WEB-INF/classes directory of a WAR file[80]
• a jar file in the WEB-INF/lib directory of a WAR file
• a jar file in the EAR library directory
• an application client jar file

JBOSS java.lang.ClassNotFoundException

We have been using JBOSS-4.2.1 as our application server .
I am trying to load a class (com.sting.ui.saas.reporting.ReportExecutor) . The fully qualified path of this class has been externalized and written in the properties file. This properties file is kept in /bin/properties directory of JBOSS
I am getting the exception
java.lang.ClassNotFoundException: No ClassLoaders found for: com.sting.ui.saas.reporting.ReportExecutor
at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:514)
at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:408)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
The class is present in /WEB_INF/com/sting/ui/saas/reporting/ReportExecutor.class.
In my properties file I have written -
report.executor.class=com.sting.ui.saas.reporting.ReportExecutor
The properties directory itself is added to the classpath from run.bat file.
I think WEB-INF is not valid place for classes. Change its place to WEB-INF/classes directory.. Or jar that class , and put the jar file to WEB-INF/lib directory..

Can I make a WAR depend on a JNDI entry in JBoss 5.1?

As part of an upgrade from JBoss 4.0.4 to 5.1, I am trying to get a WAR to deploy after an EAR is successfully deployed. JBoss 5.x does not support PrefixDeploymentSorter like 4.x did, which means that I have to use <depends> in the WAR's jboss-web.xml.
It seems I cannot depend on the EAR itself, so I pick the last deployed EJB instead. This EJB provides a JNDI entry that the WAR needs.
Here's the EJB as it deploys when the WAR is absent from the deploy directory:
2010-03-25 10:47:30,348 INFO [org.jboss.ejb3.session.SessionSpecContainer] (main) Starting jboss.j2ee:ear=my-ear.ear,jar=mypackage-ejb.jar,name=MyFacadeBean,service=EJB3
2010-03-25 10:47:30,350 INFO [org.jboss.ejb3.EJBContainer] (main) STARTED EJB: my.package.MyFacadeBean ejbName: MyFacadeBean
2010-03-25 10:47:30,371 INFO [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (main) Binding the following Entries in Global JNDI:
my/MyFacade/local - EJB3.x Default Local Business Interface
my-ear/MyFacadeBean/local-my.package.MyFacade - EJB3.x Local Business Interface
And here's the depends snippet from jboss-web.xml:
<depends>jboss.j2ee:ear=my-ear.ear,jar=mypackage-ejb.jar,name=MyFacadeBean,service=EJB3</depends>
My problem is: The WAR starts to deploy immediately after "STARTED EJB:", i.e. before MyFacadeBean is bound to JNDI, which causes bean deployments to fail:
2010-03-25 10:47:39,068 ERROR [my.facade.FacadeFactory] (main) MyFacade not bound
2010-03-25 10:47:39,069 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[my.host.no].[/]] (main) StandardWrapper.Throwable
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at my.freemarker.servlet.FreemarkerController.setupPojoServiceFactory(FreemarkerController.java:621)
[...]
Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: MyFacade not bound
at my.facade.FacadeFactory.getFacade(FacadeFactory.java:61)
After the WAR has finished its deployment, MyFacade happily (mockingly?) continues its deployment and binds the JNDI entries.
If I hot-deploy the WAR after the EAR has deployed, everything works as intended.
I even thought of depending on a dummy EJB in the EAR, and using <module-order>strict</module-order> in jboss-app.xml to force it to load as the last module. But alas, JBoss 5.x does not support that either. Doh!
Is there a way to depend on the JNDI entry itself? Are there other ways of solving this?
Here's how you can achieve this on JBoss 5.1.x.
First, add a file called aliases.txt into the META-INF directory of your EAR. This file should just contain a single line with an arbitrary name / identifier for your EAR. For example, if you have my-ear.ear, your META-INF/aliases.txt file could contain 'my-ear'. It just needs to be something that won't clash with any other aliases declared by other apps deployed on the same server.
Next, add a jboss-dependency.xml file to the META-INF directory of your WAR, containing the following (subsituting 'my-ear' for the alias you created above):
<dependency xmlns="urn:jboss:dependency:1.0">
<item whenRequired="Real" dependentState="Create">my-ear</item>
</dependency>
This will ensure the EAR is deployed before the WAR.
Also, if you try to deploy the WAR without the EAR being present, JBoss will log a clear deployment error message telling you about the missing dependency.