Use WildFly module both datasource and connectionFactory - java

I have a module in Wildfly to use as my datasource to Firebird. It works great
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.firebirdsql">
<resources>
<resource-root path="jaybird-2.2.13.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.resource.api"/>
<module name="javax.xml.bind.api"/> <!-- Jaybird 3.0 onwards doesn't need this -->
<module name="org.antlr4"/>
</dependencies>
</module>
and the jar is put inside the directory of module.xml.
But I want to use the driver both with data source and also to create a pure JDBC connection in connectionfactory like Class.forName("org.firebirdsql.jdbc.FBDriver");, not using data source provided by the server.
If I put jaybird in pom.xml I got errors. I think because this is duplicating the libs. How can I solve this?

I just added the below code under <subsystem xmlns="urn:jboss:domain:ee:4.0">
<global-modules>
<module name="org.firebirdsql" slot="main"/>
</global-modules>
Thanks, Mark Rotteveel for answer on the Jaybird bug tracker.

Related

Wildfly 26 Jakarta EE 9.1

Background
Transforming a Wildfly 17 Java EE project (EAR) to Wildfly 26 and Jakarta EE9.1
Updated all dependencies and changed imports. Also some code changes necessary.
Now i am stuck on resteasy-core-spi-6.0.0.Beta1
When deploying i get this error:
Caused by: java.lang.IncompatibleClassChangeError: Expected static method 'java.lang.Object org.jboss.resteasy.spi.ResteasyProviderFactory.getContextData(java.lang.Class)'
The Code that calls this method looks like this.
FooClass foo = ResteasyProviderFactory.getContextData(FooClass .class);
A look at the SPI Class reveals this.
public static <T> T getContextData(Class<T> type) {
return getContextDataMap().get(type);
}
That looks perfectly fine.
Examining the Wildfly system dir and looking in the module for same jar.(resteasy-core-spi-6.0.0.Beta1,jar)
reveals this
<resources>
<resource-root path="resteasy-core-spi-6.0.0.Beta1.jar"/>
</resources>
<dependencies>
<module name="java.desktop"/>
<module name="java.logging"/>
<module name="java.management"/>
<module name="java.naming"/>
<module name="java.xml"/>
<module name="javax.activation.api"/>
<module name="javax.annotation.api"/>
<module name="javax.enterprise.api"/>
<module name="javax.servlet.api"/>
<module name="javax.validation.api"/>
<module name="javax.xml.bind.api"/>
<module name="javax.ws.rs.api"/>
<module name="org.jboss.logging"/>
<module name="org.reactivestreams"/>
</dependencies>
I tried to update that to jakarta namespace but no change.
I am at a loss here, do anyone have some ideas?

Need to exclude apache httpcomponent from jboss 6.4 module

We have recently migrated from jboss 6.1 eap to 6.4 eap, but facing problem of class loading.
In my project lib We need to use apache httpcore 4.4.1, but apache httpcore 4.3.3 is included in 6.4. This previously wasn't a problem when we were using jboss 6.1 because the resteasy-jaxrs module.xml did not export httpcore library.
Now with jboss 6.4 we are getting exception :
Caused by: java.lang.NoSuchMethodError: org.apache.http.util.Asserts.check(ZLjava/lang/String;Ljava/lang/Object;)V
Its because runtime my project is using jar available from jboss and which does not having this method with required signature.
Now I want to force my application to not to use jboss jar and use jar available from web-inf/lib folder.
I have try to exclude this via jboss-deployment-structure.xml but somehow it is not working and still it is using jar from jboss only.
below is snap from the jboss-deployment-structure.xml file.
<deployment>
<exclusions>
<module name="org.apache.httpcomponents" />
</exclusions>
<dependencies>
module name="org.apache.httpcomponents" />
</dependencies>
</deployment>
Can someone please help me on this what is missing here or is there any alternative for this...
Since you are using JBoss EAP, you can apply the CP07 patch for EAP 6.4 (so your version would be JBoss EAP 6.4.7) where this issue has been addressed. I would highly recommend applying the CP07 patch.
Alternatively, you can set <module name="org.apache.httpcomponents" export="false"/> in the $JBOSS_MODULES\org\jboss\resteasy\resteasy-jaxrs\main\module.xml.
However, I would recommend applying the patch as the recommended solution. This way you will not modify the configuration that is shipped with the product.
To resolve the issue we can take one of the below approach.
Change $JBOSS_MODULES\org\jboss\resteasy\resteasy-jaxrs\main\module.xml
as suggested by CoolBeans.
You can use below option if you have no control(or not authorized) to update the Jboss server configuration.
Add below xml configuration in your jboss-deployment-structure.xml file
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="resteasy"/>
<subsystem name="jaxrs"/>
</exclude-subsystems>
<!-- Exclusions allow you to prevent the server from automatically adding
some dependencies -->
<exclusions>
<module name="javax.ws.rs.api"/>
<module name="org.jboss.as.jaxrs"/>
<module name="org.jboss.resteasy.resteasy-atom-provider" />
<module name="org.jboss.resteasy.resteasy-cdi" />
<module name="org.jboss.resteasy.resteasy-jaxrs" />
<module name="org.jboss.resteasy.resteasy-jaxb-provider" />
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
<module name="org.jboss.resteasy.resteasy-jsapi" />
<module name="org.jboss.resteasy.resteasy-multipart-provider" />
<module name="org.jboss.resteasy.async-http-servlet-30" />
<module name="org.jboss.resteasy.resteasy-hibernatevalidator-provider" />
<module name="org.jboss.resteasy.resteasy-jettison-provider" />
<module name="org.jboss.resteasy.resteasy-spring" />
<module name="org.jboss.resteasy.resteasy-yaml-provider" />
</exclusions>
<dependencies>
</dependencies>
</deployment>
</jboss-deployment-structure>
This worked for me, Hope this will work for other

ClassNotFoundException org.h2.Driver in Wildfly

I am trying to deploy and run my ear file in wildfly. when I try to access following code it gives ClassNotFoundException for org.h2.Driver.
String jdbcURL = "jdbc:h2:file;MODE=Derby;auto_server=true"; Class.forName("org.h2.Driver");
Connection = DriverManager.getConnection(jdbcURL, username", "password");
My module.xml
<module xmlns="urn:jboss:module:1.1" name="com.h2database.h2">
<resources>
<resource-root path="h2.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
is any I need to Change?
WildFly already ships with a module named com.h2database.h2. I don't think you need to add your own.
As for the ClassNotFoundException, make sure your deployment has a dependency on the module com.h2database.h2. There are several ways to add a dependency to your deployment the easiest probably being to add a Dependencies: com.h2database.h2 to your MANIFEST.MF. See the class loading documentation for other ways.

JSF Mojarra is not initializing ManagedBeans in JBoss modules

My problem is (as I think) quite complicated..
I am using JBoss 7 and created a module for Liferay faces. Within my WAR file, I created a jboss-deployment-structure.xml, in which I load the JSF module with Mojarra and the Liferay Faces module. But on startup of my web application, the ManagedBeans of the Liferay Faces implementation are not initialized and because of this, my application crashes. If I include the Liferay Faces JAR in my WAR lib folder, everything works, so this something of a class loading issue..
Liferay Faces modules.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.liferay.faces">
<resources>
<resource-root path="liferay-faces-alloy.jar"/>
<resource-root path="liferay-faces-bridge-api.jar"/>
<resource-root path="liferay-faces-bridge-impl.jar"/>
<resource-root path="liferay-faces-portal.jar"/>
<resource-root path="liferay-faces-util.jar"/>
<resource-root path="util-bridges.jar"/>
<resource-root path="util-java.jar"/>
<resource-root path="util-taglib.jar"/>
<!-- Just for testing --->
<resource-root path="AlexBean.jar"/>
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.enterprise.api" />
<module name="javax.faces.api" />
<module name="javax.inject.api" />
<module name="com.liferay.portal" />
<module name="com.sun.jsf-impl" />
</dependencies>
</module>
jboss-deployment-structure.xml
[...]
<module name="com.liferay.faces" services="import" export="true" meta-inf="export"/>
<module name="com.sun.jsf-impl" />
[...]
Why do I know Mojarra is not scanning and loading the #ManagedBeans #ApplicationScoped as it should? The JAR file AlexBean.jar contains a single class which is annotated as #ManagedBean and #ApplicationScoped. If the JAR file is placed within the WAR file, it works. If I use the JBoss modules they aren't, so I assume that the Liferay Faces beans aren't loaded either, but they are needed..
Thx in advance!
Best regards - Nuker

Unable to query Infinispan on JBoss 7 due to SearchFactoryIntegrator not being in the registry

TL:DR I'm getting the following error and I can see no reason for it, indexing is enabled, and the SearchFactoryIntegrator is on the classpath for everything that needs to see it.
Indexing was not enabled on this cache. interface
org.hibernate.search.spi.SearchFactoryIntegrator not found in registry
Long Version:
JBoss version: 7.1.1 FINAL
Infinispan version: 5.16 (upgraded from 5.1.2 JBoss ships with in attempts to solve issue)
Java Version: 1.7
I am attempting to build a simple test application to run queries against an Infinispan cache.
I am successfully adding objects to the cache. The cache is defined as private org.infinispan.Cache<String, Agent> cache; with Agent being my own object.
When attempting to query the cache I get the following error from the line
SearchManager searchManager = Search.getSearchManager(cache);
17:35:43,873 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SearchableCacheTest].[Faces Servlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.IllegalArgumentException: Indexing was not enabled on this cache. interface org.hibernate.search.spi.SearchFactoryIntegrator not found in registry
at org.infinispan.query.impl.ComponentRegistryUtils.getComponent(ComponentRegistryUtils.java:40) [infinispan-query-5.1.6.FINAL.jar:5.1.6.FINAL]
at org.infinispan.query.SearchManagerImpl.<init>(SearchManagerImpl.java:56) [infinispan-query-5.1.6.FINAL.jar:5.1.6.FINAL]
at org.infinispan.query.Search.getSearchManager(Search.java:39) [infinispan-query-5.1.6.FINAL.jar:5.1.6.FINAL]
The important part being
Indexing was not enabled on this cache. interface org.hibernate.search.spi.SearchFactoryIntegrator not found in registry
Prior to this error cache.getCacheConfiguration().indexing().enabled() resolves to true
The cache is a modified version of the default "cluster" cache already configured in the standalone-ha.xml of JBoss.
<cache-container name="cluster" aliases="ha-partition" default-cache="default" start="EAGER">
<transport lock-timeout="60000"/>
<replicated-cache name="default" mode="SYNC" batching="true" indexing="LOCAL">
<locking isolation="REPEATABLE_READ"/>
<store class="org.infinispan.loaders.file.FileCacheStore" preload="true" passivation="false" fetch-state="true" purge="false">
<property name="location">
/tempCacheIndex
</property>
</store>
</replicated-cache>
</cache-container>
I see the index being created in the configured file location so it seems that enabled boolean resolving to true is a factual representation of the current state.
I have created an org.infinispan.query module in JBoss and it contains the following
avro-1.5.1.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-search-engine-4.1.1.Final.jar
infinispan-query-5.1.6.FINAL.jar
jackson-core-asl-1.9.2.jar
jackson-mapper-asl-1.9.2.jar
lucene-core-3.5.0.jar
paranamer-2.3.jar
slf4j-api-1.6.1.jar
snappy-java-1.0.4.1.jar
All of the above are defined in as resource-roots in the module.xml for that module.
I have modified the module.xml for the module org.infinispan to have a dependency on the module org.infinispan.query
I have declared dependencies on both those modules in my jboss-deployment-structure.xml
Does anyone have any ideas why this might be happening and perhaps have a solution?
Note: There is a very similar question here but he was ultimately unsuccessful and chose a different route.
NOTE: I started with a clean JBoss 7.1.1 instance and hence reverted from Infinispan 5.1.6 to 5.1.2
For my needs I modified the existing cluster cache so it looks like this
<cache-container name="cluster" aliases="ha-partition"
default-cache="default" start="EAGER">
<transport lock-timeout="60000" />
<replicated-cache name="default" mode="SYNC" batching="true"
indexing="LOCAL">
<locking isolation="REPEATABLE_READ" />
<store class="org.infinispan.loaders.file.FileCacheStore"
preload="true" passivation="false" fetch-state="true" purge="false">
<property name="location">
/tempCacheIndex
</property>
</store>
</replicated-cache>
Then to actually be able to query the cache create the org.infinispan.query module containing the jars mentioned in the following module.xml
<module xmlns="urn:jboss:module:1.1" name="org.infinispan.query">
<resources>
<resource-root path="avro-1.5.1.jar"/>
<resource-root path="hibernate-commons-annotations-4.0.1.Final.jar"/>
<resource-root path="hibernate-search-4.1.0.Beta1.jar"/>
<resource-root path="hibernate-search-analyzers-4.1.0.Beta1.jar"/>
<resource-root path="hibernate-search-engine-4.1.0.Beta1.jar"/>
<resource-root path="hibernate-search-orm-4.1.0.Beta1.jar"/>
<resource-root path="infinispan-query.jar"/>
<resource-root path="jackson-core-asl-1.9.2.jar"/>
<resource-root path="jackson-mapper-asl-1.9.2.jar"/>
<resource-root path="lucene-analyzers-3.5.0.jar"/>
<resource-root path="lucene-core-3.5.0.jar"/>
<resource-root path="lucene-grouping-3.5.0.jar"/>
<resource-root path="lucene-highlighter-3.5.0.jar"/>
<resource-root path="lucene-memory-3.5.0.jar"/>
<resource-root path="lucene-misc-3.5.0.jar"/>
<resource-root path="lucene-smartcn-3.5.0.jar"/>
<resource-root path="lucene-spatial-3.5.0.jar"/>
<resource-root path="lucene-spellchecker-3.5.0.jar"/>
<resource-root path="lucene-stempel-3.5.0.jar"/>
<resource-root path="paranamer-2.3.jar"/>
<resource-root path="slf4j-api-1.6.1.jar"/>
<resource-root path="snappy-java-1.0.4.1.jar"/>
<resource-root path="solr-analysis-extras-3.5.0.jar"/>
<resource-root path="solr-commons-csv-3.5.0.jar"/>
<resource-root path="solr-core-3.5.0.jar"/>
<resource-root path="solr-solrj-3.5.0.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="org.hibernate"/>
<module name="org.infinispan" services="import" export="true"/>
<module name="org.apache.commons.codec"/>
<module name="org.apache.commons.io"/>
<module name="org.apache.commons.lang"/>
<module name="com.google.guava"/>
<module name="org.slf4j" export="true"/>
<module name="org.jboss.logging"/>
</dependencies>
Modify the org.jboss.as.clustering.infinspan module xml to include a dependency on the new query module but also the org.hibernate module that already exists. So add the following to that file.
<module name="org.hibernate" services="import"/>
<module name="org.infinispan.query" services="import"/>
The jboss-deployment-structure.xml of your app needs to have the following dependencies added to it
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module export="true" name="org.hibernate" services="import"/>
<module export="true" name="org.infinispan" services="import"/>
<module export="true" name="org.infinispan.query" services="import"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
For annotating your objects so they can be indexed and searched I suggest you look at the samples here
EDIT:
FURTHER NOTE:
To get indexed objects to actually share over the cache I now had to
Create a jar containing all the classes that you plan to put in the cache.
Make sure these entities do not contain anything too complex it terms of imports or you'll run into class loader issues.
Create a module from this jar, and give it a dependency on the Infinispan.query module.
Expose this module as a global module (is this actually needed?) in the standalone.xml or domain.xml whichever is appropriate.
Find the file modules/org/jboss/as/clustering/infinispan/main/module.xml
Add your new module containing your cachable entities to the list of dependencies

Categories

Resources