1
votes

I have built jFairy project from git repository ([1]: https://github.com/Devskiller/jfairy.git) using mvnw install command. then I have imported compiled jar file to my project.

package userdao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.ResultSet;
import com.devskiller.jfairy.Fairy;
import com.devskiller.jfairy.producer.person.Person;
import userdao.User;
/**
 *
 * @author loveu
 */
public class UserDao {

    /**
     * @param args the command line arguments
     * @throws java.lang.ClassNotFoundException
     * @throws java.sql.SQLException
     */
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        UserDao dao = new UserDao();
        User user = new User();
        Fairy fairy = Fairy.create();
        Person person = fairy.person();
        user.setId(person.getFullName());
        user.setName(person.getFirstName());
        user.setPassword(person.getEmail());
        dao.add(user);
        System.out.println(user.getId() + "successfuly");
        User  user2 = dao.get(user.getId());
        System.out.println(user2.getName());
        System.out.println(user2.getPassword());       

        // TODO code application logic here
    }    

but while compiling, currently I have got that error

run: Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/AbstractModule at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at com.devskiller.jfairy.Fairy.create(Fairy.java:54) at userdao.UserDao.main(UserDao.java:29) Caused by: java.lang.ClassNotFoundException: com.google.inject.AbstractModule at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 14 more C:\Users\loveu\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1

How to fix that. Thanks

2

2 Answers

1
votes

You can find information about required libraries inside pom.xml, it is much easier to use tools like Apache Maven to build java applications.

    <dependency>
        <groupId>org.yaml</groupId>
        <artifactId>snakeyaml</artifactId>
        <version>1.20</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-text</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-math3</artifactId>
        <version>3.6.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>24.0-jre</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>4.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-assistedinject</artifactId>
        <version>4.2.0</version>
    </dependency>
0
votes

you need to add the class or .jar file which contains this class into the java classpath.

Have a look at this link:-

exception in thread 'main' java.lang.NoClassDefFoundError: