2

I need to cooperate with an external API in order to decode green pass, in particular i'm following the guide of https://gae-piaz.medium.com/decode-the-eu-green-pass-qrcode-using-java-b5654e55b0fc, and i use Maven dependencies adding them to the pom.xml file. When I run my java application in IntellijIDE I got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/iot/cbor/CborMap
at kapta.classes/kapta.Utils.GreenPassValidator.DecodeQRGreenPass.decode(DecodeQRGreenPass.java:43)
at kapta.classes/kapta.Utils.GreenPassValidator.MainDecodeGreenPass.main(MainDecodeGreenPass.java:10)                                                                           
Caused by: java.lang.ClassNotFoundException: com.google.iot.cbor.CborMap
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:520)
... 2 more

Here the link with the dependencies:

Dependencies

Here the link with the run configuration:

Run configuration

This is my Pom file:

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

<groupId>kapta</groupId>
<artifactId>classes</artifactId>
<version>1.0-SNAPSHOT</version>
<name>KaptaProject</name>

<properties>
 <sonar.organization>al3ssandrocaruso</sonar.organization>
 <sonar.host.url>https://sonarcloud.io</sonar.host.url>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>5.7.1</junit.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.zxing</groupId>
        <artifactId>core</artifactId>
        <version>3.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.zxing</groupId>
        <artifactId>javase</artifactId>
        <version>3.4.1</version>
    </dependency>
    <dependency>
        <groupId>io.github.ehn-digital-green-development</groupId>
        <artifactId>base45</artifactId>
        <version>0.0.3</version>
    </dependency>
    <dependency>
        <groupId>com.augustcellars.cose</groupId>
        <artifactId>cose-java</artifactId>
        <version>0.9.7</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.iot.cbor</groupId>
        <artifactId>cbor</artifactId>
        <version>0.01.02</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.augustcellars.cose</groupId>
        <artifactId>cose-java</artifactId>
        <version>0.9.4</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>17.0.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>17.0.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-web</artifactId>
        <version>17.0.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.controlsfx</groupId>
        <artifactId>controlsfx</artifactId>
        <version>11.1.0</version>
    </dependency>
    <dependency>
        <groupId>com.dlsc.formsfx</groupId>
        <artifactId>formsfx-core</artifactId>
        <version>11.3.2</version>
        <exclusions>
            <exclusion>
                <groupId>org.openjfx</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>net.synedra</groupId>
        <artifactId>validatorfx</artifactId>
        <version>0.1.13</version>
        <exclusions>
            <exclusion>
                <groupId>org.openjfx</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.kordamp.ikonli</groupId>
        <artifactId>ikonli-javafx</artifactId>
        <version>12.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.kordamp.bootstrapfx</groupId>
        <artifactId>bootstrapfx-core</artifactId>
        <version>0.4.0</version>
    </dependency>
    <dependency>
        <groupId>eu.hansolo</groupId>
        <artifactId>tilesfx</artifactId>
        <version>11.48</version>
        <exclusions>
            <exclusion>
                <groupId>org.openjfx</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>17.0.0.1</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.22</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>17</source>
                <target>17</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.7</version>
            <executions>
                <execution>
                    <!-- Default configuration for running with: mvn clean javafx:run -->
                    <id>default-cli</id>
                    <configuration>
                        <mainClass>kapta.classes/kapta.MainApp</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/java/kapta/View</directory>
            <!-- Alessandro Caruso was here :) -->
        </resource>
    </resources>
</build>

I don't know how to proceed.

1 Answers1

1

For com.google.iot.cbor dependency in pom.xml change the scope from runtime to compile (which is the default, so you can just remove the scope tag).

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • The error persists because it is at runtime and not at compile time. How can I solve it? – Manuele Mustari Feb 01 '22 at 21:43
  • If it's runtime, how do you provide this dependency to runtime application? How do you configure the app to run so that it can find this dependency? Note that runtime classpath control is up to you, IDE will not handle it for you. – CrazyCoder Feb 01 '22 at 21:53
  • How can I manage this runtime configurations? – Manuele Mustari Feb 01 '22 at 23:22
  • This is what you should tell us about your project, we don't know. – CrazyCoder Feb 02 '22 at 02:03
  • 1
    Here the links of two projects: the first works while the second not. They look the same and I don't understand why. Tell me if you need more and I will send you. Thanks. FIRST: https://github.com/ManueleMustari/GreenPass2.git SECOND: https://github.com/ManueleMustari/GreenPassManuele.git – Manuele Mustari Feb 02 '22 at 11:21
  • Has nothing to do with the dependencies configuration or IntelliJ IDEA, please see https://stackoverflow.com/questions/10583622/com-google-zxing-notfoundexception-exception-comes-when-core-java-program-execut. – CrazyCoder Feb 02 '22 at 17:29
  • My error is not **com.google.zxing.NotFoundException**. This Exception is thrown when no QRcode is found in the image. It is not my case. My image is only a QRcode so I don't need to cut it. I don't think that this is my problem. I tried to check in the Maven settings->Runner the option "Delegate IDE build/run actions to Maven" and in this case it works. So, the problem is not the resolution of the image. How can I solve it? Does it explain my real problem? I would like to run without checking maven option too... I'm using javafx and i'm encountering some problems with it. – Manuele Mustari Feb 03 '22 at 09:52
  • I get this error when trying to run your code: https://i.imgur.com/s1mqI2E.png. Maybe you should share the image as well so that the app can run furher? – CrazyCoder Feb 03 '22 at 18:22