0
我爲自定義編碼創建了新的jar文件,而我將這個jar文件添加到我的新項目中,它拋出「包不存在」和「無法找到符號」錯誤。在java應用程序中實現自定義jar獲取錯誤
的jar文件有一個類, 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();
}
}
和我的實現類是,
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 {
\t public UserService() {
\t \t super();
\t }
\t public void create(User event) throws DataAccessLayerException {
\t \t super.saveOrUpdate(event);
\t }
}
這裏我已經把AbstractDao.class文件放在jar和UserService.java中,我已經實現了AbstractDao類。
添加什麼步驟你一些描述了包括該項目的新的jar – gba
分享你的pom.xml與調試完整的堆棧跟蹤啓用 – mirmdasif
Hi @gba我已更新我的問題。 – Karthikeyan