I created a small website crawler in Java that inserts its results into a Sqlite DB using Hibernate. When I run the main method with IntelliJ everything works perfectly fine.
Now I want to build my jar file and run it but get exceptions. I tried creating the jar file using IntelliJ aswell as the maven assembly plugin but get the same results.
First I got a log4J error on private static final Logger log = LogManager.getLogger();
:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found.
at org.apache.logging.log4j.LogManager.callerClass(LogManager.java:529)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:554)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:541)
at drnuenninger.crawler.BoulderCrawler.<clinit>(BoulderCrawler.java:20)
I fixed this by supplying BoulderCrawler.class as a paramter but it's odd to me that this line of code used to work when running from IntelliJ.
But now I run into a Hibernate error on startup:
java -jar bleau.infoDBScraper.jar
2025-02-02 02:00:29 [main] INFO org.hibernate.Version - HHH000412: Hibernate ORM core version [WORKING]
2025-02-02 02:00:30 [main] INFO org.hibernate.cache.internal.RegionFactoryInitiator - HHH000026: Second-level cache disabled
2025-02-02 02:00:30 [main] WARN org.hibernate.orm.connections.pooling - HHH10001002: Using built-in connection pool (not intended for production use)
2025-02-02 02:00:30 [main] INFO org.hibernate.orm.connections.pooling - HHH10001005: Database info:
Database JDBC URL [jdbc:sqlite:bleau.info.scraped.db]
Database driver: org.sqlite.JDBC
Database version: 3.48
Autocommit mode: false
Isolation level: undefined/unknown
Minimum pool size: 1
Maximum pool size: 20
Exception in thread "main" java.lang.ExceptionInInitializerError: SessionFactory creation failed: org.hibernate.MappingException: Could not create DynamicParameterizedType for type: null
at drnuenninger.HibernateHelper.<clinit>(HibernateHelper.java:25)
at drnuenninger.entities.dao.BaseDAO.<clinit>(BaseDAO.java:17)
at drnuenninger.crawler.BoulderCrawler.getUnfinishedBoulderAreas(BoulderCrawler.java:85)
at drnuenninger.crawler.BoulderCrawler.parse(BoulderCrawler.java:96)
at drnuenninger.crawler.BoulderCrawler.main(BoulderCrawler.java:34)
my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<groupId>drnuenninger</groupId>
<artifactId>bleau.infoDBScraper</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>drnuenninger.crawler.BoulderCrawler</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.48.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.6.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-community-dialects</artifactId>
<version>6.6.5.Final</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.24.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.24.3</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.54</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I have looked into the generated jar file and confirmed that the dependencies and hibernate config file exist. I have tried different methods or generating the jar file. Through IntelliJ, maven assembly and maven shade. All resulted in the same error(s).
I would expect that the program runs the same as if I start it with IntelliJ. Instead I got the log4J exception and now the hibernate exception when running the jar file.
Both issues could be fixed by including this in my Manifest.mf file:
Multi-Release: true