Unable to Add JAR to Vanilla Java Project
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.
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.
I was having the same issue, but i tried what @sachsgit suggested, and everything works now! Thanks!
Thanks! @sachsgit
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