0

I am trying to use the gson library on a project, which I execute via java -jar, the problem I encountered is that the gson dependency is not being added to it.

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>

    <groupId>es.batoipop</groupId>
    <artifactId>Chat</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <name>Chat</name>
    <url>https://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.8</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>es.batoipop.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

The error I get is this one:

This has never happened before, and I have been searching for a while but I have not found nothing to solve it

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
geikov
  • 11
  • 2
  • Your configuration for creating a JAR with dependencies looks incomplete. Please have a look at [the answers of this question](https://stackoverflow.com/q/574594). – Marcono1234 Feb 23 '22 at 22:17
  • @Marcono1234 yeah that definitely worked, don't know why i did not tried that before, thank you so much. – geikov Feb 23 '22 at 23:25

0 Answers0