5
I am developing a Java, FX, Hibernate application and using log4j2 for my logs. When I run the application through the IDE (Eclipse) everything works normally, but when creating the . application jar, the following errors appear (just at the time of starting the database in Hibernate) :
26/01/2016 11:22:32.186 [ INFO] LogHelper.java:31 - HHH000204: Processing PersistenceUnitInfo [
name: crp
...]
26/01/2016 11:22:32.243 [ INFO] Version.java:37 - HHH000412: Hibernate Core {5.0.7.Final}
26/01/2016 11:22:32.248 [ INFO] Environment.java:198 - HHH000205: Loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false}
26/01/2016 11:22:32.250 [ INFO] Environment.java:317 - HHH000021:Bytecode provider name : javassist
26/01/2016 11:22:32.293 [ INFO] JavaReflectionManager.java:66 - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
26/01/2016 11:22:33.761 [ERROR] Conexao.java:20 - Erro em Persistence.createEntityManagerFactory(crp) => Unable to build entity manager factory javax.persistence.PersistenceException: Unable to build entity manager factory at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:66)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at br.org.eldorado.crp.util.Conexao.<clinit>(Conexao.java:18)
at br.org.eldorado.crp.controller.Tasks$2.call(Tasks.java:39)
at br.org.eldorado.crp.controller.Tasks$2.call(Tasks.java:1)
at javafx.concurrent.Task$TaskCallable.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.apache.logging.log4j.core.appender.
db.jpa.converter.ContextMapJsonAttributeConverter]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:232)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.applyScanResultsToManagedResources(ScanningCoordinator.java:235)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:81)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:98)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:194)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
... 8 more
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/type/TypeReference
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:226)
... 17 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.type.TypeReference
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 20 more
26/01/2016 11:22:33.863 [ERROR] MainController.java:433 - Falha ao conectar com o banco de dados!
I am totally lost in where the error may be. Please, someone can give some help, at least to understand what is happening.
Thank you very much.
You can confirm that all dependencies have been added next to . jar?
– dougg0k
Java is new to me, so I’m going to have a hard time with some things. Renaming . jar and opening with a zip I see Hibernate, FX and my software inside (all models and all controllers). What I was in doubt is about log4j2. It has a log4j inside the Apache folder and a slf4j. I think this is from log4j2. How to see dependencies in more detail? Thanks @Douglas-Aldino
– Tulio F. Polachini
SLF4J is a facade for logs in Java, it is like an interface, an abstraction for several log libraries, but for this interface to work, it needs the implementation chosen by the developer, some existing are Log4j2, Logback, Simple Log, etc. So in addition to the SLF4J dependency, in your case you need Log4j 1.2 or 2, one of the two depending on which version/Binding of slf4j you chose. To look in more detail, without using any dependency manager, is to look for folders even.
– dougg0k
@Douglasgaldino, please correct me if I’m wrong. One of the errors generated is
ClassNotFoundException: com.fasterxml.jackson.core.type.TypeReference
. This fasterxml doesn’t really exist on my .jar. Would I have to add it to my project? I don’t use it directly. Who uses it? Thank you.– Tulio F. Polachini
It seems to be a branch of Jackson, which is a data format processing library such as XML and JSON. It’s always nice to use dependency managers like Maven/Gradle poís in a case like this, it’s usually solved automatically by the manager, it downloads all the dependencies pertaining to that library you’re using. But to solve it in your case try adding this library. http://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
– dougg0k
Adding the jars
com.fasterxml.jackson.annotations.jar
andcom.fasterxml.jackson.databind.jar
the problem has been solved. Thank you very much @Douglasgaldino– Tulio F. Polachini
As solved with other dependencies, you can put an answer with the solution and accept the same as answer. It was nothing :]
– dougg0k