java.lang.NoClassDefFoundError: org/jooq/SelectField
Closed this issue ยท 13 comments
OS: macOS 12.3 (x86_64)
Model: MacBook Pro (Retina, 15-inch, Mid 2015)
Java: openjdk version "18" 2022-03-22
Maven: Apache Maven 3.8.5
Hi, I'm very new to Java and don't have much knowledge of it. I'm running into an issue running the project. Following the SETUP.md doc, I've managed to prepare everything including osm2pgsql and running the afterwards script. I could build the project with mvn clean install
and the bulid process was fine.
The issue came when I tried to run the target with java -jar target/here2osm-1.0-SNAPSHOT.jar
. The command fails with one of these exceptions randomly (if I run it multiple times):
Exception in thread "main" java.lang.NoClassDefFoundError: org/jooq/SelectField
at Here2Osm.main(Here2Osm.java:9)
Caused by: java.lang.ClassNotFoundException: org.jooq.SelectField
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
Exception in thread "main" java.lang.NoClassDefFoundError: org/jooq/Table
at Here2Osm.main(Here2Osm.java:9)
Caused by: java.lang.ClassNotFoundException: org.jooq.Table
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
Any help or hint is appreciated. Thanks!
Hi mogita,
it would be nice if you could reveal what is hidden behind "... 1 more", so I could maby find an error in code.
Other than that I don't really have a clue, sorry.
so, I have looked into the setup again and think it should work.
Mabye you forgot to keep the Database running in the background.
Or it has something to do with your device, but I don't know anything about mac...
Hi @Y4nn1k8, thank you for the advice. I made sure the database was running (it was a service so it was available at any time), however the error still existed.
I don't know how can I expand "... 1 more" with Java. Searched and found the error actually came from src/java/main/Here2OSM.java:9
, where it calls ApiRequest request = new ApiRequest();
and it went error. This is all I can understand for now.
Fiddling with the code, I made some change in src/main/java/HereApi/ApiRequest.java
:
- import org.jooq.*;
+ import org.jooq.DSLContext;
+ import org.jooq.Field;
+ import org.jooq.SQLDialect;
+ import org.jooq.Name;
Unfortuatelly it didn't work.
Also, I tried wrapping everything up into a docker-compose
file and ran it on a cloud machine running Ubuntu 20.04, it turned out to be the exact same error.
The base image for compiling and running java
was openjdk:11-jdk-buster
, and for database pgrouting/pgrouting:13-3.1-3.1.3
. And again I made sure database was reachable by the containers since psql
and osm2pgsql
comamnds executed successfully.
FYI here's the content of my Dockerfile
:
FROM openjdk:11-jdk-buster
ARG HERE_API_KEY
ARG PBF_URL
ARG MAP_NAME
ARG MAP_OWNER
RUN apt-get update && apt-get -y install maven osm2pgsql
RUN java -version
RUN mvn -version
WORKDIR /app
COPY . /app
RUN chmod a+x /app/wait-for-it.sh
RUN chmod a+x /app/run.sh
And here's the script run.sh
:
#!/bin/bash
set -e
export PGPASSWORD=here2osm
echo "============================================="
echo "Creating extensions in database..."
echo "============================================="
echo ""
psql -U here2osm -d here2osm -h here2osm-db -c "CREATE EXTENSION IF NOT EXISTS hstore;"
psql -U here2osm -d here2osm -h here2osm-db -c "CREATE EXTENSION IF NOT EXISTS postgis;"
psql -U here2osm -d here2osm -h here2osm-db -c "CREATE EXTENSION IF NOT EXISTS pgrouting;"
echo "============================================="
echo "Importing map and creating openlr metadata..."
echo "============================================="
echo ""
wget $PBF_URL -O /usr/map.osm.pbf
osm2pgsql -c -d here2osm -U here2osm -H here2osm-db --hstore -S /usr/share/osm2pgsql/default.style /usr/map.osm.pbf
psql -U here2osm -d here2osm -h here2osm-db -f /app/import-openlr.sql
psql -U here2osm -d here2osm -h here2osm-db << EOF
INSERT INTO openlr.metadata(map_name, map_owner) VALUES ('$MAP_NAME', '$MAP_OWNER');
EOF
echo "============================================="
echo "Building here2osm..."
echo "============================================="
echo ""
mvn clean install
echo "============================================="
echo "Starting here2osm..."
echo "============================================="
echo ""
java -jar /app/target/here2osm-1.0-SNAPSHOT.jar
And finally the relavent parts of database connection configs:
Apology for the mess. It's a shame I didn't know Java better. Hoping it was something I missed that's obvious to the Java experts. Thank you so much!
Dear @mogita,
the Stacktrace indicates that the maven plugin jooq-codegen-maven
did not generate the classes that are needed to communicate with the database.
After running mvn install, these classes should exist in the folder "target/generated-sources/jooq" and also inside the jar. It actually surprises me that mvn install ran through with these classes not existing.
Can you please check, if they exist?
If they do not exist, then the plugin "jooq-codegen-maven" may have been misconfigured (even though your configuration seems okay as far as I can judge). But in this case, it should report some error/warning message during mvn install. Can you please check this?
Would it be possible for you to provide the resulting jar-file ?
Thanks also for your code example. We are currently considering to externalize dbUrl, user and password from the class DatasourceConfig to an external config file. Once this would be finished, it would be possible for us to provide a jar file that actually contains the required classes, since they are correctly generated in the environments that we use.
If it is not possible to generate the classes on your side, we may help by providing the generated sources and resulting classes for our environment. They may work in your environment as well.
Hi @stefanhahmann, here are my findings according to your guidance:
- The relevant part in
pom.xml
is identical to your screenshot - The files under
target/generated-sources/jooq
andtarget/classes/org
:
> tree target/generated-sources/jooq
target/generated-sources/jooq
โโโ org
โโโ jooq
โโโ sources
โโโ DefaultCatalog.java
โโโ Indexes.java
โโโ Keys.java
โโโ Openlr.java
โโโ Tables.java
โโโ tables
โโโ FormOfWay.java
โโโ FunctionalRoadClass.java
โโโ Kanten.java
โโโ Knoten.java
โโโ Metadata.java
โโโ records
โโโ FormOfWayRecord.java
โโโ FunctionalRoadClassRecord.java
โโโ KantenRecord.java
โโโ KnotenRecord.java
โโโ MetadataRecord.java
5 directories, 15 files
---
> tree target/classes/org
target/classes/org
โโโ jooq
โโโ sources
โโโ DefaultCatalog.class
โโโ Indexes$Indexes0.class
โโโ Indexes.class
โโโ Keys$ForeignKeys0.class
โโโ Keys$UniqueKeys0.class
โโโ Keys.class
โโโ Openlr.class
โโโ Tables.class
โโโ tables
โโโ FormOfWay.class
โโโ FunctionalRoadClass.class
โโโ Kanten.class
โโโ Knoten.class
โโโ Metadata.class
โโโ records
โโโ FormOfWayRecord.class
โโโ FunctionalRoadClassRecord.class
โโโ KantenRecord.class
โโโ KnotenRecord.class
โโโ MetadataRecord.class
4 directories, 18 files
Did a quick grep and didn't find "SelectField" class among the files.
mvn clean install
did left some warnings. Here's the full log:
Click to expand the full log
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.example:here2osm:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.version' for org.jetbrains:annotations:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 113, column 22
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------< org.example:here2osm >------------------------
[INFO] Building here2osm 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ here2osm ---
[INFO] Deleting /Users/mogita/Developer/src/here-openlr/target
[INFO]
[INFO] --- jooq-codegen-maven:3.12.3:generate (default) @ here2osm ---
[INFO] Database : Inferring database org.jooq.meta.postgres.PostgresDatabase from URL jdbc:postgresql://localhost/openlr
[INFO] No <inputCatalog/> was provided. Generating ALL available catalogs instead.
[INFO] License parameters
[INFO] ----------------------------------------------------------
[INFO] Thank you for using jOOQ and jOOQ's code generator
[INFO]
[INFO] Database parameters
[INFO] ----------------------------------------------------------
[INFO] dialect : POSTGRES
[INFO] URL : jdbc:postgresql://localhost/openlr
[INFO] target dir : /Users/mogita/Developer/src/here-openlr/target/generated-sources/jooq
[INFO] target package : org.jooq.sources
[INFO] includes : [.*]
[INFO] excludes : []
[INFO] includeExcludeColumns : false
[INFO] ----------------------------------------------------------
[INFO]
[INFO] JavaGenerator parameters
[INFO] ----------------------------------------------------------
[INFO] annotations (generated): true
[INFO] annotations (JPA: any) : false
[INFO] annotations (JPA: version):
[INFO] annotations (validation): false
[INFO] comments : true
[INFO] comments on attributes : true
[INFO] comments on catalogs : true
[INFO] comments on columns : true
[INFO] comments on keys : true
[INFO] comments on links : true
[INFO] comments on packages : true
[INFO] comments on parameters : true
[INFO] comments on queues : true
[INFO] comments on routines : true
[INFO] comments on schemas : true
[INFO] comments on sequences : true
[INFO] comments on tables : true
[INFO] comments on udts : true
[INFO] daos : false
[INFO] deprecated code : true
[INFO] global references (any): true
[INFO] global references (catalogs): true
[INFO] global references (keys): true
[INFO] global references (links): true
[INFO] global references (queues): true
[INFO] global references (routines): true
[INFO] global references (schemas): true
[INFO] global references (sequences): true
[INFO] global references (tables): true
[INFO] global references (udts): true
[INFO] indexes : true
[INFO] instance fields : true
[INFO] interfaces : false
[INFO] interfaces (immutable) : false
[INFO] javadoc : true
[INFO] keys : true
[INFO] links : true
[INFO] pojos : false
[INFO] pojos (immutable) : false
[INFO] queues : true
[INFO] records : true
[INFO] routines : true
[INFO] sequences : true
[INFO] table-valued functions : true
[INFO] tables : true
[INFO] udts : true
[INFO] relations : true
[INFO] ----------------------------------------------------------
[INFO]
[INFO] Generation remarks
[INFO] ----------------------------------------------------------
[INFO]
[INFO] ----------------------------------------------------------
[INFO] Generating catalogs : Total: 1
[INFO]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@ @@ @@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@
@@@@@@@@@@@@@@@@ @@ @@ @@@@@@@@@@
@@@@@@@@@@ @@@@ @@ @@ @@@@@@@@@@
@@@@@@@@@@ @@ @@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@ @@ @@@@@@@@@@
@@@@@@@@@@ @@ @@ @@@@ @@@@@@@@@@
@@@@@@@@@@ @@ @@ @@@@ @@@@@@@@@@
@@@@@@@@@@ @@ @ @ @@@@@@@@@@
@@@@@@@@@@ @@ @@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Thank you for using jOOQ 3.12.3
[INFO] ARRAYs fetched : 0 (0 included, 0 excluded)
[INFO] Enums fetched : 0 (0 included, 0 excluded)
[INFO] Packages fetched : 0 (0 included, 0 excluded)
[INFO] Routines fetched : 0 (0 included, 0 excluded)
[INFO] Sequences fetched : 0 (0 included, 0 excluded)
[INFO] Tables fetched : 5 (5 included, 0 excluded)
[INFO] No schema version is applied for catalog . Regenerating.
[INFO]
[INFO] Generating catalog : DefaultCatalog.java
[INFO] ==========================================================
[INFO] Generating schemata : Total: 1
[INFO] No schema version is applied for schema openlr. Regenerating.
[INFO] Generating schema : Openlr.java
[INFO] ----------------------------------------------------------
[INFO] UDTs fetched : 0 (0 included, 0 excluded)
[INFO] Generating tables
[INFO] Adding foreign key : kanten__end_node_fk (openlr.kanten.end_node) referencing knoten_pkey
[INFO] Adding foreign key : kanten__fow_fk (openlr.kanten.fow) referencing form_of_way_pkey
[INFO] Adding foreign key : kanten__frc_fk (openlr.kanten.frc) referencing functional_road_class_pkey
[INFO] Adding foreign key : kanten__start_node_fk (openlr.kanten.start_node) referencing knoten_pkey
[INFO] Synthetic primary keys : 0 (0 included, 0 excluded)
[INFO] Overriding primary keys : 4 (0 included, 4 excluded)
[INFO] Generating table : FormOfWay.java [input=form_of_way, output=form_of_way, pk=form_of_way_pkey]
[INFO] Embeddables fetched : 0 (0 included, 0 excluded)
[INFO] Indexes fetched : 10 (10 included, 0 excluded)
[INFO] Generating table : FunctionalRoadClass.java [input=functional_road_class, output=functional_road_class, pk=functional_road_class_pkey]
[INFO] Generating table : Kanten.java [input=kanten, output=kanten, pk=kanten_pkey]
[INFO] Generating table : Knoten.java [input=knoten, output=knoten, pk=knoten_pkey]
[INFO] Generating table : Metadata.java [input=metadata, output=metadata, pk=N/A]
[INFO] Tables generated : Total: 653.677ms
[INFO] Generating table references
[INFO] Table refs generated : Total: 655.18ms, +1.502ms
[INFO] Generating Keys
[INFO] Keys generated : Total: 659.342ms, +4.162ms
[INFO] Generating Indexes
[INFO] Indexes generated : Total: 662.129ms, +2.786ms
[INFO] Generating table records
[INFO] Generating record : FormOfWayRecord.java
[INFO] Generating record : FunctionalRoadClassRecord.java
[INFO] Generating record : KantenRecord.java
[INFO] Generating record : KnotenRecord.java
[INFO] Generating record : MetadataRecord.java
[INFO] Table records generated : Total: 690.572ms, +28.442ms
[INFO] Domains fetched : 0 (0 included, 0 excluded)
[INFO] Generation finished: openlr: Total: 704.269ms, +13.697ms
[INFO]
[INFO] Removing excess files
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ here2osm ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ here2osm ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 56 source files to /Users/mogita/Developer/src/here-openlr/target/classes
[INFO] /Users/mogita/Developer/src/here-openlr/src/main/java/OpenLRImpl/LineImpl.java: Some input files use or override a deprecated API.
[INFO] /Users/mogita/Developer/src/here-openlr/src/main/java/OpenLRImpl/LineImpl.java: Recompile with -Xlint:deprecation for details.
[INFO] /Users/mogita/Developer/src/here-openlr/src/main/java/Loader/RoutableOSMMapLoader.java: Some input files use unchecked or unsafe operations.
[INFO] /Users/mogita/Developer/src/here-openlr/src/main/java/Loader/RoutableOSMMapLoader.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ here2osm ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/mogita/Developer/src/here-openlr/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ here2osm ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ here2osm ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ here2osm ---
[INFO] Building jar: /Users/mogita/Developer/src/here-openlr/target/here2osm-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ here2osm ---
[INFO] Installing /Users/mogita/Developer/src/here-openlr/target/here2osm-1.0-SNAPSHOT.jar to /Users/mogita/.m2/repository/org/example/here2osm/1.0-SNAPSHOT/here2osm-1.0-SNAPSHOT.jar
[INFO] Installing /Users/mogita/Developer/src/here-openlr/pom.xml to /Users/mogita/.m2/repository/org/example/here2osm/1.0-SNAPSHOT/here2osm-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.243 s
[INFO] Finished at: 2022-04-04T19:06:30+08:00
[INFO] ------------------------------------------------------------------------
- And finally here's the built artifact:
Okay. This would indicate that the programm cannot find/access the external libraries that are used by it (and currently the are not included in the resulting jar file - this could also be improved by us).
You could try the following:
java -Djava.library.path=\Users\mogita.m2\repository* -jar here2osm-1.0-SNAPSHOT.jar
Now we changed the jar-file generation, so it should contain the External Libraries too.
Hoping it will work now!
(you have to execute java -jar target\here2osm.jar instead of here2osm-1.0-SNAPSHOT)
Thank you guys! I've pulled the latest code and it worked!
Good to hear. For your information: we are currently working on supporting a newer version of HERE API. That will support not only incidents but also traffic flow.
That is awesome. Traffic flow capability would be so great.