Home > database >  Hibernate Search doesn't work when converting to jar
Hibernate Search doesn't work when converting to jar

Time:09-22

I have an application that uses hibernate search. I've been developing it locally, and it's been working fine within IntelliJ. When I export it to a jar file and run that though, I get an issue with Hibernate Search initializing.

It gives me an error about a bean not being available for "None" for the property "hibernate.search.coordination.strategy". The hibernate docs says this property is optional. This also isn't a problem when I run my code from IntelliJ. Only when I compile a jar, and run it from the command line.

I'm using:

Hibernate 6.1.3

Hibernate Search 6.1.7

Hibernate Search Mapper orm orm6 6.1.7

Hibernate Search Backend Lucene 6.1.7

I use Mavern for the dependencies if that's helpful. Here's my full pom.xml

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

    <properties>
        <java.version>18</java.version>
    </properties>

    <groupId>groupId</groupId>
    <artifactId>KanjiBattleServer</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>18</source>
                    <target>18</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>18</source>
                    <target>18</target>
                    <compilerArguments>
                        <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>4.0.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.29</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.1.3.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>6.1.3.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-mapper-orm-orm6</artifactId>
            <version>6.1.7.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-backend-lucene</artifactId>
            <version>6.1.7.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-mapper-orm-coordination-outbox-polling-orm6</artifactId>
            <version>6.1.7.Final</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.6</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>5.0.0</version>
        </dependency>


        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>4.2.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.53.Final</version>
        </dependency>


    </dependencies>


</project>

I'm not sure if it's an issue with how I'm building the jar or what, since other dependencies seem to do fine ( like Netty ).

Below is the full error:

java.lang.ExceptionInInitializerError
        at com.company.Utils.AdminServerConnections.getUserFromDB(AdminServerConnections.java:73)   
        at com.company.Utils.AdminServerConnections.getUser(AdminServerConnections.java:38)
        at com.company.ConnectionResponse.processAdminCommand(ConnectionResponse.java:93)
        at com.company.AdminConnectionHandler.channelRead(AdminConnectionHandler.java:68)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302)   
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:1
03)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.ja
va:93)
        at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.
java:82)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandshakeHandler.channelRea
d(WebSocketServerProtocolHandshakeHandler.java:65)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:1
03)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannel
Read(CombinedChannelDuplexHandler.java:436)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324
)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)   
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.ja
va:251)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.ja
va:1410)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) 
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.jav
a:166)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)    
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:9
89)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)    
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.hibernate.search.util.common.SearchException: HSEARCH000501: Invalid value for config
uration property 'hibernate.search.coordination.strategy': ''. HSEARCH000579: Unable to resolve bean
 reference to type 'org.hibernate.search.mapper.orm.coordination.common.spi.CoordinationStrategy' an
d name 'none'. Failed to resolve bean from Hibernate Search's internal registry with exception: HSEA
RCH000578: No beans defined for type 'org.hibernate.search.mapper.orm.coordination.common.spi.Coordi
nationStrategy' and name 'none' in Hibernate Search's internal registry. Failed to resolve bean from
 bean manager with exception: HSEARCH000590: No configured bean manager. Failed to resolve bean from
 bean manager with exception: HSEARCH000591: Unable to resolve 'none' to a class extending 'org.hibe
rnate.search.mapper.orm.coordination.common.spi.CoordinationStrategy': HSEARCH000530: Unable to load
 class 'none': Could not load requested class : none Failed to resolve bean using reflection with ex
ception: HSEARCH000591: Unable to resolve 'none' to a class extending 'org.hibernate.search.mapper.o
rm.coordination.common.spi.CoordinationStrategy': HSEARCH000530: Unable to load class 'none': Could 
not load requested class : none
        at org.hibernate.search.engine.cfg.impl.AbstractConfigurationProperty.doGet(AbstractConfigur
ationProperty.java:61)
        at org.hibernate.search.engine.cfg.impl.AbstractConfigurationProperty.getAndTransform(Abstra
ctConfigurationProperty.java:36)
        at org.hibernate.search.mapper.orm.coordination.impl.CoordinationConfigurationContextImpl.co
nfigure(CoordinationConfigurationContextImpl.java:38)
        at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateSearchPreIntegrationService.coord
inationStrategyConfiguration(HibernateSearchPreIntegrationService.java:193)
        at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateSearchCompositeMappingProducer.pr
oduceAdditionalMappings(HibernateSearchCompositeMappingProducer.java:50)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingPro
cess.java:329)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProces
s.java:97)
        at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:402)      
        at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:90)       
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:735)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:773)
        at com.company.UtilDatabase.<clinit>(UtilDatabase.java:18)
        ... 52 more
Caused by: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH000579: Un
able to resolve bean reference to type 'org.hibernate.search.mapper.orm.coordination.common.spi.Coor
dinationStrategy' and name 'none'. Failed to resolve bean from Hibernate Search's internal registry 
with exception: HSEARCH000578: No beans defined for type 'org.hibernate.search.mapper.orm.coordinati
on.common.spi.CoordinationStrategy' and name 'none' in Hibernate Search's internal registry. Failed 
to resolve bean from bean manager with exception: HSEARCH000590: No configured bean manager. Failed 
to resolve bean from bean manager with exception: HSEARCH000591: Unable to resolve 'none' to a class
 extending 'org.hibernate.search.mapper.orm.coordination.common.spi.CoordinationStrategy': HSEARCH00
0530: Unable to load class 'none': Could not load requested class : none Failed to resolve bean usin
g reflection with exception: HSEARCH000591: Unable to resolve 'none' to a class extending 'org.hiber
nate.search.mapper.orm.coordination.common.spi.CoordinationStrategy': HSEARCH000530: Unable to load 
class 'none': Could not load requested class : none
        at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFirstSucces
sfulSource(BeanResolverImpl.java:173)
        at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolve(BeanResolverIm
pl.java:91)
        at org.hibernate.search.engine.environment.bean.TypeAndNameBeanReference.resolve(TypeAndName
BeanReference.java:28)
        at org.hibernate.search.engine.environment.bean.BeanResolver.resolve(BeanResolver.java:75)  
        at org.hibernate.search.engine.cfg.impl.DefaultedConfigurationProperty.convert(DefaultedConf
igurationProperty.java:27)
        at org.hibernate.search.engine.cfg.impl.AbstractConfigurationProperty.doGet(AbstractConfigur
ationProperty.java:44)
        ... 63 more
        Suppressed: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH0
00590: No configured bean manager.
                at org.hibernate.search.engine.environment.bean.impl.NoConfiguredBeanManagerBeanProv
ider.forTypeAndName(NoConfiguredBeanManagerBeanProvider.java:37)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.tryResolve(Bea
nResolverImpl.java:196)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFir
stSuccessfulSource(BeanResolverImpl.java:162)
                ... 68 more
        Suppressed: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH0
00591: Unable to resolve 'none' to a class extending 'org.hibernate.search.mapper.orm.coordination.c
ommon.spi.CoordinationStrategy': HSEARCH000530: Unable to load class 'none': Could not load requeste
d class : none
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.toClass(BeanRe
solverImpl.java:211)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.tryResolve(Bea
nResolverImpl.java:198)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFir
stSuccessfulSource(BeanResolverImpl.java:162)
                ... 68 more
        Caused by: org.hibernate.search.engine.environment.classpath.spi.ClassLoadingException: HSEA
RCH000530: Unable to load class 'none': Could not load requested class : none
                at org.hibernate.search.engine.environment.classpath.spi.DefaultClassResolver.classF
orName(DefaultClassResolver.java:39)
                at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmClassLoaderServiceClas
sAndResourceAndServiceResolver.classForName(HibernateOrmClassLoaderServiceClassAndResourceAndService
Resolver.java:60)
                at org.hibernate.search.engine.environment.classpath.spi.ClassLoaderHelper.classForN
ame(ClassLoaderHelper.java:174)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.toClass(BeanRe
solverImpl.java:208)
                ... 70 more
        Caused by: java.lang.ClassNotFoundException: Could not load requested class : none
                at org.hibernate.search.engine.environment.classpath.spi.AggregatedClassLoader.findC
lass(AggregatedClassLoader.java:108)
                at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
                at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
                at java.base/java.lang.Class.forName0(Native Method)
                at java.base/java.lang.Class.forName(Class.java:488)
                at java.base/java.lang.Class.forName(Class.java:467)
                at org.hibernate.search.engine.environment.classpath.spi.DefaultClassResolver.classF
orName(DefaultClassResolver.java:36)
                ... 73 more
        Suppressed: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH0
00591: Unable to resolve 'none' to a class extending 'org.hibernate.search.mapper.orm.coordination.c
ommon.spi.CoordinationStrategy': HSEARCH000530: Unable to load class 'none': Could not load requeste
d class : none
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.toClass(BeanRe
solverImpl.java:211)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.tryResolve(Bea
nResolverImpl.java:200)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFir
stSuccessfulSource(BeanResolverImpl.java:162)
                ... 68 more
        Caused by: org.hibernate.search.engine.environment.classpath.spi.ClassLoadingException: HSEA
RCH000530: Unable to load class 'none': Could not load requested class : none
                at org.hibernate.search.engine.environment.classpath.spi.DefaultClassResolver.classF
orName(DefaultClassResolver.java:39)
                at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmClassLoaderServiceClas
sAndResourceAndServiceResolver.classForName(HibernateOrmClassLoaderServiceClassAndResourceAndService
Resolver.java:60)
                at org.hibernate.search.engine.environment.classpath.spi.ClassLoaderHelper.classForN
ame(ClassLoaderHelper.java:174)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.toClass(BeanRe
solverImpl.java:208)
                ... 70 more
        Caused by: java.lang.ClassNotFoundException: Could not load requested class : none
                at org.hibernate.search.engine.environment.classpath.spi.AggregatedClassLoader.findC
lass(AggregatedClassLoader.java:108)
                at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
                at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
                at java.base/java.lang.Class.forName0(Native Method)
                at java.base/java.lang.Class.forName(Class.java:488)
                at java.base/java.lang.Class.forName(Class.java:467)
                at org.hibernate.search.engine.environment.classpath.spi.DefaultClassResolver.classF
orName(DefaultClassResolver.java:36)
                ... 73 more
Caused by: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH000578: No
 beans defined for type 'org.hibernate.search.mapper.orm.coordination.common.spi.CoordinationStrateg
y' and name 'none' in Hibernate Search's internal registry.
        at org.hibernate.search.engine.environment.bean.impl.ConfigurationBeanRegistry.resolve(Confi
gurationBeanRegistry.java:53)
        at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.tryResolve(BeanResolve
rImpl.java:194)
        at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFirstSucces
sfulSource(BeanResolverImpl.java:162)
        ... 68 more

CodePudding user response:

Asked on the hibernate forums and figured out the answer. The issue is that IntelliJ isn't packaging things correctly when building the Jar. The fix was to open up the jar and add the line: org.hibernate.search.mapper.orm.impl.HibernateOrmBeanConfigurer

to the file at META-INF/services/org.hibernate.search.engine.environment.bean.spi.BeanConfigurer

on a new line. So the file looks like this after editing:

org.hibernate.search.engine.impl.EngineBeanConfigurer
org.hibernate.search.mapper.orm.impl.HibernateOrmBeanConfigurer

Then the jar will execute correctly with Hibernate Search

  • Related