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

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.

Related

Trying to deploy EAR in JBOSS 7.3. EJB.jar is not being looked up by the application in classpath

The structure of EAR is like this
EAR - Contains lmsweb.war and lmsEJB.jar
After deploying , when the application is trying to lookup at the bean, getting error as below
Unable to Get NamingException :javax.naming.CommunicationException: EJBCLIENT000062: Failed to look up "lms/lmsEJB/ejb/TestHome!com.lms.ejb.test.TestHome" [Root exception is java.lang.ClassNotFoundException: com.lms.ejb.test.TestHome from [Module "deployment.lms.ear.lmsWeb.war" from Service Module Loader]]
This class is inside the ejb module i.e., "deployment.lms.ear.lmsEJB.jar"
Can someone throw light on how to make the application look into the ejb module to get the class.

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?

Need strategy for identifying root cause of "JBAS011232: Only one JAX-RS Application Class allowed"

I have a problem similar to my previous one. I have a webapp that runs fine in JBoss EAP 6.4. I want to add some functionality to my webapp so that it can manipulate a hive-metastore. I add a single dependency to my pom.xml:
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>3.1.2</version>
</dependency>
If I now try to start my webapp, it fails at start up:
15:07:37,718 ERROR [org.jboss.msc.service.fail] (MSC service thread
1-5) MSC000001: Failed to start service
jboss.deployment.unit."myapp-0.0.1-SNAPSHOT.war".POST_MODULE:
org.jboss.msc.service.StartException in service
jboss.deployment.unit."myapp-0.0.1-SNAPSHOT.war".POST_MODULE:
JBAS018733: Failed to process phase POST_MODULE of deployment
"myapp-0.0.1-SNAPSHOT.war"
... Caused by:
org.jboss.as.server.deployment.DeploymentUnitProcessingException:
JBAS011232: Only one JAX-RS Application Class allowed.
com.sun.jersey.api.core.servlet.WebAppResourceConfig
com.sun.jersey.api.core.DefaultResourceConfig
com.sun.jersey.server.impl.application.DeferredResourceConfig
com.sun.jersey.api.core.ClassNamesResourceConfig
org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig
org.glassfish.jersey.server.ResourceConfig
org.glassfish.jersey.server.ResourceConfig$RuntimeConfig
com.sun.jersey.api.core.ScanningResourceConfig
com.sun.jersey.api.core.ResourceConfig
com.sun.jersey.api.core.PackagesResourceConfig
com.mycompany.RestApplication
com.sun.jersey.api.core.ApplicationAdapter
com.sun.jersey.api.core.ClasspathResourceConfig
The message "JBAS011232: Only one JAX-RS Application Class allowed" seems to be caused by my webapp trying to use both RestEasy (v. 2.3.10.Final-redhat-1) and Jersey. JBoss uses RestEasy by default. Apparently, hive-jdbc must directly or indirectly have a Jersey application class.
I would like to eliminate this problem by indicating that I don't want to use a Jersey-based application class. What strategy can I employ to discover where that Jersey-based class exists? If I generate the dependency tree with mvn,
mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=true
hive-jdbc has nearly 800 lines of dependencies. There must be a better strategy than looking through the source code of all of the dependencies. Or, is there somehow a way to tell JBoss to ignore Jersey application classes?
BTW, unlike my previous question, hadoop-common doesn't seem to be the culprit. When I look at the occurrences of "hadoop-common" in the dependency tree, I see the following:
My current strategy goes like this:
Repeat
add exclusion to likely looking package in pom file
start JBoss and examine console log
if console log has no JBAS01132 error then
if console log has no startup failure due to NoClassDefFound error then
Done!
else remove exclusion
until Done
I can't get to "done". At this point, I seem to be stuck on the jersey-server package. Without it being present, we get the NoClassDefFound error. With it, we get JBAS011232: Only one JAX-RS Application Class allowed.

Wildfly 10 can't find my jar resources

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.

Wrong war file name in deployment directory

I am having a "404 Not found" error message when visiting at:
http://localhost:8080/bword in Eclipse.
This application is served in Wildfly. In POM.xml, it defines:
<artifactId>bword</artifactId>
<packaging>war</packaging>
<name>bword</name>
However, strange enough, when I run the application in Eclipse with Wildfly 9.0 configured as the server, what's deployed into wildfly/standone/deployments/ is bbword.war, as below:
[abigail#localhost wildfly-9.0.2.Final]$ ls standalone/deployments/
bbword.war/ bbword.war.deployed
Which is wrong, it should be "bword.war/" and "bword.war.deployed".
Outside of Eclipse, if I "mvn clean package" under the project "bword", I can get the "bword.war" under the target/ directory.
Please see the attachment screenshot for reference. I suspect somewhere in my pom, or eclipse, or whatever place, there is a misconfiguration of "bbword", instead of "bword", but I can't really find it. I can't find any trace of "bbword". What dictates the name of the deployed war file under deployments?
See attached.
Edited (Part of the POM.xml):
<build>
<!-- Set the name of the war, used as the context root when the app
is deployed -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- WildFly plugin to deploy war -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates
annotation processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler.plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
One more addition:
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
17:32:35,508 INFO [org.jboss.modules] (main) JBoss Modules version 1.4.3.Final
17:32:35,702 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
17:32:35,761 INFO [org.jboss.as] (MSC service thread 1-6) WFLYSRV0049: WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final) starting
17:32:36,573 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 22) WFLYCTL0028: Attribute 'job-repository-type' in the resource at address '/subsystem=batch' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
17:32:36,594 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found bbword.war in deployment directory. To trigger deployment create a file called bbword.war.dodeploy
17:32:36,625 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
17:32:36,647 INFO [org.xnio] (MSC service thread 1-5) XNIO version 3.3.1.Final
......
This is the very initial section of the console message after I click "Run as Server" on Wildfly. It seems that it shows "Found bbword.war in deployment directory." Before I run it, I delete all in standalone/deployments/*. It start with an empty directory. It seems the "bbword.war" is copied to this directory whenever I run the server. I can't figure out. I use "find / -name bbword.war" on my computer but can't find this file. Really puzzled.
Update on this:
Eventually found out the problem: under the project 'bword', there is a ".setting" directory, which contains this file:
bword/.settings/org.eclipse.wst.common.component
And there is a line in it: , where "bbword" was the previous deploy name I used. Remove this directory and in Maven, run "update" seems fixing this problem. In particular, I need to do both, first delete this dirctory, .setting, then update maven.
Several days wasted on this, but it's good to know about this.
Had the same issue and fixed it by having corrected those 2 files :
.settings/org.eclipse.wst.common.component
=>deploy-name, etc
.project
=>name
First, try deploying the maven-built artifact (bword.war) on your server(Do not forget to completely clean-up any Eclipse deployed artifacts first).
You can do this by simply moving the bword.war from your /target folder to your path_to_wildfly/standalone/deployments folder.
Check the server log file for message: Registered web context: <web_context_name> that should appear once your war is deployed.
If it says /bbword - which is not what you expect, check whether you have a jboss-web.xml file in src/main/webapp/WEB-INF that specifies this as a web-context value.
If the maven artifact results in correct webcontext - /bword, then it must be an Eclipse configuration issue. Have you tried updating the Eclipse project from Maven? :
right click on your project
select Maven
select Update Project
remove your project from Wildfly server, and add it again. If that does not help, try adding a new server runtime and add your project there. Last resort would be to create a new Eclipse workspace.
Good luck.
The listed solutions didnt work for me.
I had to create a completely new project in eclipse:
File->New->Project
named it correctly, and then copy-pasted the necessary code from the old project.
Now the server name is correct.
If you'e running from intellij idea config then checkout artifact name in project structure. I had to rename it manually after fixing finalname tag in pom.xml. Better avoid any timestamp in artifact name.