Eclipse ne détecte pas les jars "jdom" que j'ai ajouté
bnj à tous,
je voudrais executer un code java avec l'utilisation de jdom
j'ai intéger dans mon projet les jars:jdom4.Xcerces"projet,proprités,buildpath,add external jars,mais qd j'écrit mon code il m'affiche:
Citation:
the import org.jdom can not be resolved
voici le code
Code:
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
| import java.io.*;
import org.jdom.*;
import org.jdom.output.*;
public class JDOM1
{
//Nous allons commencer notre arborescence en créant la racine XML
//qui sera ici "personnes".
static Element racine = new Element("personnes");
//On crée un nouveau Document JDOM basé sur la racine que l'on vient de créer
static org.jdom.Document document = new Document(racine);
public static void main(String[] args)
{
Element etudiant = new Element("etudiant");
racine.addContent(etudiant);
Attribute classe = new Attribute("classe","P2");
etudiant.setAttribute(classe);
Element nom = new Element("nom");
nom.setText("CynO");
etudiant.addContent(nom);
affiche();
enregistre("Exercice1.xml");
}
static void affiche()
{
try
{
XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
sortie.output(document, System.out);
}
catch (java.io.IOException e){}
}
static void enregistre(String fichier)
{
try
{
XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
sortie.output(document, new FileOutputStream(fichier));
}
} |
et quand je fais "run as java application" il m'affiche:
Citation:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Element cannot be resolved to a type
Element cannot be resolved to a type
racine cannot be resolved
Attribute cannot be resolved to a type
Attribute cannot be resolved to a type
Element cannot be resolved to a type
Element cannot be resolved to a type
at package1.JDOM1.main(JDOM1.java:20)
que faire? merci a++
j'ai eu le meme pb mais c ok
Donc je te propose une solution qui pour moi a fonctionné. J'ai pas mal galérer avant de trouver...
Donc dans ton JRE System Library tu met "jdom.jar" dans la librairie. Il faut également qu tu créer un dossier nommé "lib" dans ton projet et que tu insères le jdom.jar.Il faut ensuite que dans le MANIFEST.MF dans la fenetre MANIFEST.MF tu rajoute ce ci:
Bundle-ClassPath: .,
lib/jdom.jar
normalement apres cela ca fonctionne. Etrange que ce jdom qui ne s'insère pas aussi facilement que les autres
Bon courage a toi !:king: