2016-04-26 8 views
0

Ich erstellte neue JAR-Datei für meine benutzerdefinierte Codierung, während ich diese JAR-Datei zu meinem neuen Projekt hinzufügen, es wirft "Paket existiert nicht" und "kann Symbol nicht finden" Fehler.Fehler beim Implementieren von benutzerdefinierten jar in Java-Anwendung

Die JAR-Datei haben eine Klasse, 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(); 
 
    } 
 
}

und meine Implementierungsklasse war,

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 } 
 
}

Hier habe ich AbstractDao.class Datei in das Glas und in UserService.java habe ich die AbstractDao Klasse implementiert.

Dieser Fehler ist, ich bekam, enter image description here

+1

einige weitere Beschreibung auf fügen Sie, welche Schritte Sie nahm das neue Glas in das Projekt einzubeziehen Ihre pom.xml und komplette Stack-Trace mit Debug – gba

+0

Teile aktiviert – mirmdasif

+0

Hallo @gba Ich habe meine Frage aktualisiert. – Karthikeyan

Antwort

4

Der mögliche Grund für Fehler ist, dass Sie nicht richtig Ihre benutzerdefinierten jar auf Ihrem lokalen Maven-Repository installiert haben.

So installieren Sie Ihr JAR wie folgt in Ihrem lokalen Repository.

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

Siehe auch diese Frage How to add local jar files in maven project?

Verwandte Themen