IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Java Discussion :

Comment se servir de JNotify


Sujet :

API standards et tierces Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 17
    Par défaut Comment se servir de JNotify
    Bonjour, j'ai vu Que Jnotify faisait ça
    JNotify is a java library that allow java application to listen to file system events, such as:

    * file created.
    * file modified.
    * file renamed.
    * file deleted.

    Le problème c'est que je n'ai rien compris sur la façon de l'intégrer à mon système.

    Si quelqu'un peut m'aider(http://jnotify.sourceforge.net/)

    J'ai fait (j'ai decompadter l'archive dans Home/user/Jnotify/
    To use JNotify, you need to have the native library (jnotify.dll or jnotify.so) in your java.library.path. to do that, you need to use the -Djava.library.path prameter when you run the java application. for example:
    java -cp jnotify.jar -Djava.library.path=/home/user/Jnotify/libjnotify.so

  2. #2
    Invité
    Invité(e)
    Par défaut
    Salut,

    Dans le tutoriel il est écrit :
    java -cp jnotify.jar -Djava.library.path=.
    où "." représente un répertoire (en l'occurrence le répertoire courant) or la ligne que tu donnes est le chemin vers le fichier .so
    Tu dois donner là le chemin vers le répertoire contenant le .so ou le .dll et pas le fichier en soi

    A plus

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 17
    Par défaut
    Merci mais je fais quoi après avec ça ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    // to add a watch : 
    String path = System.getProperty("user.home");
     
    // watch mask
    int mask = JNotify.FILE_CREATED  |  JNotify.FILE_DELETED  |  JNotify.FILE_MODIFIED  |  JNotify.FILE_RENAMED;
     
    //watch subtree?
    boolean watchSubtree = true;
     
    // add actual watch
    int watchID = JNotify.addWatch(path, mask, watchSubtree, new JNotifyListenerImpl());
     
    // sleep a little, the application will exit if you 
    // don't (watching is asynchrnous), depending on your 
    // application, this may not be required
    try
    {
            Thread.sleep(1000000);
    }
    catch (InterruptedException e1)
    {
    }
     
    // to remove watch the watch
    boolean res = JNotify.removeWatch(watchID);
    if (!res)
    {
            // invalid watch ID specified.
    }

  4. #4
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par geoffreybulle Voir le message
    Merci mais je fais quoi après avec ça ?

    // to add a watch :
    String path = System.getProperty("user.home");

    // watch mask
    int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED | JNotify.FILE_MODIFIED | JNotify.FILE_RENAMED;

    //watch subtree?
    boolean watchSubtree = true;

    // add actual watch
    int watchID = JNotify.addWatch(path, mask, watchSubtree, new JNotifyListenerImpl());

    // sleep a little, the application will exit if you
    // don't (watching is asynchrnous), depending on your
    // application, this may not be required
    try
    {
    Thread.sleep(1000000);
    }
    catch (InterruptedException e1)
    {
    }

    // to remove watch the watch
    boolean res = JNotify.removeWatch(watchID);
    if (!res)
    {
    // invalid watch ID specified.
    }
    Qu'est-ce que tu veux dire ? Ça c'est l'exemple qui montre comment surveiller le répertoire de l'utilisateur. À toi de l'adapter avec ce que tu veux faire. En lisant l'exemple, ça parait assez simple à utiliser, tu enregistres un listener pour les événements que tu veux sur le répertoire souhaité. Quel est ton problème exactement ?

    PS : pense à utiliser la balise [code] (le bouton # quand tu édites ton messages)

  5. #5
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    Faudrait déja savoir ce que tu veux faire.

    Mais ce code te permet d'enregistrer un listener sur un dossier.

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 17
    Par défaut
    bon j'ai plusieurs problèmes :
    je me place dans le répertoire Jnotify
    cd /home/user/Jnotify

    je fais java -cp jnotify.jar -Djava.library.path=.

    Et là j'ai java qui me déroule les bon usages de la commande java avec toutes ses options.

    Le deuxième point qui me trouble : j'ai bien compris l'histoire du code. Mais j'ai cherché dans toutes les classes de Jnotify pour trouver le morceau de code exemple et y insérer le répertoire à surveiller mais je ne l'ai pas trouvé.

    Du coup je me demande s'il faut réécrire une classe contenant le code exemple.

    Merci de m'éclairer

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 17
    Par défaut
    Donc je me réponds ayant eu une grande aide extérieure

    il faut écrire une nouvelle class (Par ex SurveillanceFichiers)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    import net.contentobjects.jnotify.*;
     
    public class SurveillanceFichiers implements JNotifyListener {
     
     
     
    	public SurveillanceFichiers (){
     
     
    		// Recuperation du repertoire de travail
    		String path = "/home/user";
    		System.out.println ("Surveillance de "+path);
     
    		//Pour savoir ce qu'on va surveiller (ici tout)
    		int mask = JNotify.FILE_CREATED  |  JNotify.FILE_DELETED  |  JNotify.FILE_MODIFIED  |  JNotify.FILE_RENAMED;
     
    		boolean surveilleSousRepertoire = true; // Pour surveiller ou non les sous repertoires
    		try {
    			int watchID = JNotify.addWatch(path, mask, surveilleSousRepertoire, this);
    		} catch (JNotifyException ex) {
    			ex.printStackTrace();
    		} 
    		try {
    Thread.sleep(1000000);
    } catch (InterruptedException e1) {
    }
    	}
     
     
     
    	public void fileRenamed(int wd, String rootPath, String oldName, String newName) {
    		System.out.println("file Renomme");
     
    	}
     
    	public void fileModified(int wd, String rootPath, String name) {
    		System.out.println("file Modif");
    	}
     
    	public void fileDeleted(int wd, String rootPath, String name) {
    		System.out.println("file Delet");
    	}
     
    	public void fileCreated(int wd, String rootPath, String name) {
    		System.out.println("file cree");
     
    	}
     
    	public static void main (String args []){
    		new SurveillanceFichiers ();
    	}
    }
    L'enregistrer dans le répertoire qui contient JNotify
    puis dans une console : Compiler

    javac -cp jnotify.jar:. SurveillanceFichiers1.java
    puis lancer

    java -cp jnotify.jar:. -Djava.library.path=. SurveillanceFichiers
    Un énorme merci pour mon aide Extérieure.

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 23
    Par défaut
    bonjour,


    pourrais tu m'expliquer comment tu a procédé pour mettre en place SurveillanceFichier.java
    -où tu l'a placé.
    -où a-tu exécute la commande javac.


    Merci

Discussions similaires

  1. Réponses: 9
    Dernier message: 09/02/2010, 23h59
  2. comment se servir de dirent.h ?
    Par gronaze dans le forum C
    Réponses: 3
    Dernier message: 26/07/2006, 16h40
  3. Comment se servir du ttimer?
    Par Jayceblaster dans le forum Delphi
    Réponses: 7
    Dernier message: 12/07/2006, 14h20
  4. [LoginModule][Jboss] Comment se servir des Login Module ?
    Par kurtalis dans le forum Wildfly/JBoss
    Réponses: 8
    Dernier message: 11/05/2006, 11h01
  5. Comment se servir de la tangente en c++?
    Par c++debut dans le forum C++
    Réponses: 1
    Dernier message: 08/04/2006, 11h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo