DiUS / java-faker

Brings the popular ruby faker gem to Java
http://dius.github.io/java-faker
Other
4.74k stars 846 forks source link

Unable to Add JAR to Vanilla Java Project #599

Open ayunas opened 3 years ago

ayunas commented 3 years ago

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

To Reproduce

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:

Additional context Add any other context about the problem here.

sachsgit commented 3 years ago

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.

AguuSz commented 3 years ago

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

AllanCapistrano commented 3 years ago

Thanks! @sachsgit

FritschAuctores commented 3 years ago

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