Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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>
                what does mean "is not found"? do you receive a Maven error? in this case, show us this error.
– logoff
                Jun 19, 2014 at 10:24
                for it to be found in the maven repository you should run maven clean install first time when you add a new library to you pom file
– 4aRk Kn1gh7
                Jun 19, 2014 at 10:25
                I'm working on netbeans. In my java file I write Gson gson = new Gson(). then I click to the right in "Search dependencies in Maven repository..." but when the dialog window open it show me "No matching result"
– Mazzy
                Jun 19, 2014 at 10:26

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.

I have the same problem as OP but in Eclipse. This works but I just can't get any auto-completion. Can this be related to Gson itself? – nyg May 14, 2016 at 13:32 Struggled with this for a few hours until I found this post. I know it's a couple of years old but it still applies, at least to some Eclipse distributions. – BigTFromAZ Feb 19, 2018 at 18:32

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.