Added by Gson in pom.xml but not found

I added gson to my pom.xml . Here. But when I call Gson gson = new Gson()and try to search the maven repository, it does not find any element. What for? Where am I wrong?

<?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>
    <parent>
    <artifactId>VolaConNoi_webapp</artifactId>
    <groupId>it.volaconnoi</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

    <groupId>it.volaconnoi</groupId>
    <artifactId>VolaConNoi_webapp-ear</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>ear</packaging>

    <name>VolaConNoi_webapp-ear</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <version>6</version>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>it.volaconnoi</groupId>
            <artifactId>VolaConNoi_webapp-ejb</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>it.volaconnoi</groupId>
            <artifactId>VolaConNoi_webapp-web</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <!--  Gson: Java to Json conversion -->
        <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.2.4</version>
          <scope>compile</scope>
        </dependency>
    </dependencies>
</project>

EDIT

enter image description here

+4
source share
1 answer

Please add this to your pom.xml file in the project . This will tell maven to load the libraries that you include in the pom file, here:

<repositories>
    <repository>
      <id>central</id>
      <name>Maven repository</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>

And your code would be something like this:

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

Gson gson = new GsonBuilder().create();

And refer to this guide on how to use Gson if you need help too.

+2
source

Source: https://habr.com/ru/post/1545210/


All Articles