1

I was looking for a Random name generator and found https://github.com/DiUS/java-faker on GitHub. There it says:

In pom.xml, add the following XML stanza between <dependencies> ... </dependencies>

<dependency>
    <groupId>com.github.javafaker</groupId>
    <artifactId>javafaker</artifactId>
    <version>0.16</version>
</dependency>"

I am not familiar with Maven or Gradle or how it works, nor did the documentation of Maven really help me with importing this library into my Java project in Eclipse.

Would be thankful for any guidance (links) towards the documentation/info I need in order to understand how to use this library via either Maven or Gradle. Is this actually that complicated? Why can I not just download and add the library to my build path?

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
freeprogramer233
  • 193
  • 2
  • 11
  • 1
    Is your question about how to get the library and download it manually? If you need to use Maven or Gradle (which you probably should), then you have to use them correctly (such as by including `` tags inside `` elements. If you want to get the jar for the maven dependency, then you can browse the central repository and download manually (just be aware that you'd have to manage transitive dependencies by hand - and this project has them): https://search.maven.org/artifact/com.github.javafaker/javafaker/0.16/jar – ernest_k Nov 23 '18 at 18:54
  • 1
    You must create a Maven project then add that dependency in pom.xml file inside element. I'm afraid you'll have to learn a little bit about Maven in order to use it. Same about Gradle. –  Nov 23 '18 at 18:54
  • 1
    Do you have Maven installed? –  Nov 23 '18 at 19:03
  • 1
    Once you have the `` tags inside `` run the maven goal `dependency:resolve` at the directory where `pom.xml` is located, generally it will be something like `mvn dependency:resolve` make sure you run with at least java 8 with the env variables et all. – nmorenor Nov 23 '18 at 19:17
  • I'll look into these topics (maven and gradle) in more depth soon, the problem was that I didnt haven Maven installed in the first place, but it's working fine now after using madheads guide, thanks! – freeprogramer233 Nov 24 '18 at 14:22

1 Answers1

1

Gradle

  1. Make sure you have Gradle installed by running gradle -version.
  2. Create a directory for your project and navigate into it. Open a terminal.
  3. Execute gradle wrapper. You'll see gradlew and gradlew.bat files and gradle and .gradle directories created. From now on, you can forget about global Gradle installation as you can use wrapper. Wrapper can be used even when Gradle is not installed.
  4. Create a file named build.gradle. It's a project descriptor in Gradle:

    plugins {
        id 'java'
    }
    
    repositories {
        jcenter()
    }
    
    dependencies {
        implementation("com.github.javafaker:javafaker:0.16")
    }
    
  5. Import the project in Eclipse.

Maven

  1. Make sure you have Maven installed by running mvn -version.
  2. Create a directory for your project and navigate into it.
  3. Create a file named pom.xml or build.gradle. It's a project descriptor in Maven:

    <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>com.your.company</groupId>
        <artifactId>app</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>com.github.javafaker</groupId>
                <artifactId>javafaker</artifactId>
                <version>0.16</version>
            </dependency>
        </dependencies>
    </project>
    
  4. Import the project in Eclipse.

Is this actually that complicated?

As you see, no, it's not complex at all!

Why can I not just download and add the library to my build path?

You can. This approach just don't scale when you have dozens and hundreds of dependencies (with their own dependencies). Plus, modern software needs not only to be compiled, but tested, packaged, released & distributed. Though you can do most of that from your IDE, but… This appriach just don't scale. Just because people use different IDEs. Because there is no IDE on a build server. Because when you know Gradle or Maven a little bit better, you'll see that it's even faster to accomplish tasks via build tool then via menu items.

Happy hacking!

madhead
  • 31,729
  • 16
  • 153
  • 201
  • 1
    Now that was quite easy, thanks a lot. I am going to look into maven and gradle asap to learn about these things anyway, but for now your step by step guidance worked like a charm and I could import the libraries via maven dependencies. Thank you very much! – freeprogramer233 Nov 24 '18 at 14:21