0

I created new jar file for my custom coding, while i add this jar file to my new project it throws "package does not exist" and "cannot find symbol" errors.

The jar file have a class, AbstractDao.class

package kar;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.Query;

import java.util.List;

public abstract class AbstractDao {
    private Session session;
    private Transaction tx;

    public AbstractDao() {
        HibernateFactory.buildIfNeeded();
    }

    protected void saveOrUpdate(Object obj) {
        try {
            startOperation();
            session.saveOrUpdate(obj);
            tx.commit();
        } catch (HibernateException e) {
            handleException(e);
        } finally {
            HibernateFactory.close(session);
        }
    }

    protected void delete(Object obj) {
        try {
            startOperation();
            session.delete(obj);
            tx.commit();
        } catch (HibernateException e) {
            handleException(e);
        } finally {
            HibernateFactory.close(session);
        }
    }

    protected Object find(Class clazz, Long id) {
        Object obj = null;
        try {
            startOperation();
            obj = session.load(clazz, id);
            tx.commit();
        } catch (HibernateException e) {
            handleException(e);
        } finally {
            HibernateFactory.close(session);
        }
        return obj;
    }

    protected List findAll(Class clazz) {
        List objects = null;
        try {
            startOperation();
            Query query = session.createQuery("from " + clazz.getName());
            objects = query.list();
            tx.commit();
        } catch (HibernateException e) {
            handleException(e);
        } finally {
            HibernateFactory.close(session);
        }
        return objects;
    }

    protected void handleException(HibernateException e) throws DataAccessLayerException {
        HibernateFactory.rollback(tx);
        throw new DataAccessLayerException(e);
    }

    protected void startOperation() throws HibernateException {
        session = HibernateFactory.openSession();
        tx = session.beginTransaction();
    }
}

and my implementation class was,

UserService.java

package obs.service;

import kar.AbstractDao;
import kar.DataAccessLayerException;
import obs.domain.User;

import org.springframework.stereotype.Service;

@Service("IUserService")
public class UserService extends AbstractDao {


 public UserService() {
  super();
 }

 public void create(User event) throws DataAccessLayerException {
  super.saveOrUpdate(event);
 }
}

Here i have placed AbstractDao.class file inside the jar and in UserService.java i have implemented the AbstractDao class.

This is error i got, enter image description here

1 Answers1

4

The possible reason for your error is that you have not properly installed your custom jar to your local maven repository.

To install your jar to your local repository as follows.

mvn install:install-file
   -Dfile=<path-to-file>
   -DgroupId=<group-id>
   -DartifactId=<artifact-id>
   -Dversion=<version>
   -Dpackaging=<packaging>
   -DgeneratePom=true

Where: <path-to-file>  the path to the file to load
   <group-id>      the group that the file should be registered under
   <artifact-id>   the artifact name for the file
   <version>       the version of the file
   <packaging>     the packaging of the file e.g. jar

Reference

Also see this question How to add local jar files in maven project?

Community
  • 1
  • 1
mirmdasif
  • 6,014
  • 2
  • 22
  • 28