Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1638 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  hibernate.cfg.xml fichier introuvable

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

hibernate.cfg.xml fichier introuvable

n°1968293
vengaboys
Posté le 22-02-2010 à 20:36:39  profilanswer
 

Bonjour à tous,
Je suis en train de suivre le http://docs.jboss.org/hibernate/st [...] ersistence de hibernate, et quand j'exécute la commande maven :

Citation :

mvn exec:java -Dexec.mainClass="org.hibernate.tutorial.EventManager" -Dexec.args="store"


je me shope l'erreur suivante :

Citation :

INFO] [exec:java {execution: default-cli}]
18 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
20 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - hibernate.properties not found
24 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
29 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
130 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
130 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. null
 
/hibernate.cfg.xml not found
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch


Je pense qu'il ne trouve pas le fichier hibernate.cfg.xml car il n'est pas dans le CLASSPATH, mais je ne sais pas comment définir le CLASSPATH comme étant un attribut du plugin maven-exec.
Le fichier hibernate.cfg.xml est bien présent dans le target : /classes/org/hibernate/tutorial/domain.
D'avance merci de votre aide.

mood
Publicité
Posté le 22-02-2010 à 20:36:39  profilanswer
 

n°1968322
souk
Tourist
Posté le 22-02-2010 à 21:37:04  profilanswer
 

bah il cherche /hibernate.cfg.xml pas /org/hibernate/tutorial/domain/hibernate.cfg.xml donc normal qu'il le trouve pas [:souk]

n°1968324
vengaboys
Posté le 22-02-2010 à 21:49:56  profilanswer
 

Oui mais moi je ne veux pas qu'il le cherche dans la racine. je veux faire en sorte que maven aille le chercher depuis ce chemin : target/classes/org/hibernate/tutorial/domain car c'est là où il y est.
et je ne vois pas à quelle moment il faut que je lui indique cela.
Merci de ta réponse.

n°1968326
souk
Tourist
Posté le 22-02-2010 à 21:59:29  profilanswer
 

nan, il faut que tu dises a hibernate d'aller le chercher la ou il est, maven il s'en fout, il execute juste ta main classe. ton fichier est dans le classpath, mais hibernate le prend par defaut a la racine

n°1968354
vengaboys
Posté le 22-02-2010 à 23:57:42  profilanswer
 

Merci pour ta réponse. :)
As tu une idée sur comment il faut faire pour indiquer à hibernate le chemin d'où il va chercher le hibernate.cfg.xml?
 
Merci encore une fois.

n°1968357
souk
Tourist
Posté le 23-02-2010 à 00:07:10  profilanswer
 

comment tu construits ta SessionFactory?

n°1968831
vengaboys
Posté le 24-02-2010 à 11:24:34  profilanswer
 

souk a écrit :

comment tu construits ta SessionFactory?


La voici:
 

Citation :

public class HibernateUtil {
 
    private static final SessionFactory sessionFactory = buildSessionFactory();
 
    private static SessionFactory buildSessionFactory() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            return new Configuration().configure().buildSessionFactory();
        }
        catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
 
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

n°1968875
vengaboys
Posté le 24-02-2010 à 12:58:52  profilanswer
 

Voici l réponse :
Il faut indiquer le fichier vers hibernate.cfg.xml, dans cette ligne de commande :

Code :
  1. return new Configuration().configure("/path/to/hibernate.cfg.xml" ).buildSessionFactory();


J'espère que cela aidera les autres. ;)


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  hibernate.cfg.xml fichier introuvable

 

Sujets relatifs
Lecture d'un fichier en Fortranrequete HTTPService et fichier xml
Lire un fichier excel depuis VB.NETRemplir un tableau à partir d'un fichier
Problème Fonctionnement fichier Excelinsérer image dans un fichier php
[ANT] Ouvrir un fichier avec commande[Batch] Extraire dans un nom complet de fichier UNC le nom du fichier
[Perl] Comment envoyer le contenu d'un fichier text par mailBatch : chercher un fichier puis lui ajouter des lignes
Plus de sujets relatifs à : hibernate.cfg.xml fichier introuvable


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR