java-faker icon indicating copy to clipboard operation
java-faker copied to clipboard

Unable to Add JAR to Vanilla Java Project

Open ayunas opened this issue 4 years ago • 4 comments

Describe the bug Exception in thread "main" java.lang.NoClassDefFoundError: org/yaml/snakeyaml/Yaml

To Reproduce

  • Download the JAR file 1.0.2 from Maven - https://repo1.maven.org/maven2/com/github/javafaker/javafaker/1.0.2/javafaker-1.0.2.jar
  • Add it to a Vanilla Java Project (No Maven)
  • Instantiate a new Faker()
public static void main(String[] args) throws IOException {
     import com.github.javafaker.*;
     Faker faker = new Faker();
     String name = faker.name().name();
     System.out.println(name);
}

Expected behavior I expected a random name to be returned as a String to print out. Instead, got the NoClassDefFound errror.

Versions:

  • OS: Mac OSX 10.15.4 - Catalina
  • JDK - 11
  • Faker Version 1.0.2

Additional context Add any other context about the problem here.

ayunas avatar Jan 31 '21 18:01 ayunas

Interesting...

Not tried to use Java-Faker without Maven before, and know I appreciate Maven more.

There are two dependencies that are needed to be added if you don't use Maven (which handles it for you). You need to add "snakeyaml-1.23.jar" to your project, to solve "Exception in thread "main" java.lang.NoClassDefFoundError: org/yaml/snakeyaml/Yaml".

After which, I got "Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils" Which meant I had to add apache's "commons-lang3.3.11.jar" to my project as well.

I would recommend using Maven to help with dependencies, but if not, you need to download snakeyaml.jar at a minimum, to get JavaFaker to work. Not sure why the build didn't include those jar files, but should get you going.

sachsgit avatar Jan 31 '21 19:01 sachsgit

I was having the same issue, but i tried what @sachsgit suggested, and everything works now! Thanks!

AguuSz avatar Apr 06 '21 18:04 AguuSz

Thanks! @sachsgit

AllanCapistrano avatar Oct 02 '21 20:10 AllanCapistrano

I also needed these jars:

https://mvnrepository.com/artifact/com.github.mifmif/generex/1.0.2 https://mvnrepository.com/artifact/dk.brics.automaton/automaton/1.11-8

FritschAuctores avatar Oct 07 '21 15:10 FritschAuctores