Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Added Gson to the pom.xml but is not found

Tags:

java

xml

maven

gson

I have added gson to my pom.xml. Here is it. But when I call Gson gson = new Gson() and try so search in maven repository it doesn't found any element. Why? Where do 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

like image 728
Mazzy Avatar asked Jun 19 '14 10:06

Mazzy


People also ask

How to execute pom xml?

For this right-click the pom. xml file and select Run As Maven build. This opens a dialog which allows to define the parameters for the start. Enter clean verify in the Goals: field and press the Run button.

How to Create a Maven project and Add dependency?

Add a Java Maven Dependency to the Utility ProjectRight-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.

What is GSON API?

Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of.


1 Answers

Kindly add this to your pom.xml file under project This would tell maven to download the libraries you include in the pom file from here:

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

And your code will be something like this:

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

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

And consult this guide on how to use Gson in case you need help using it too.

like image 84
4aRk Kn1gh7 Avatar answered Sep 23 '22 06:09

4aRk Kn1gh7