Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Fichier JAR et resources internes aux fichier JAR

5 réponses
Avatar
Bernard Koninckx
Bonjour à tous,

J'ai essayé de mettre mes fichiers XML, DTD et classes de test dans un
fichier Jar avec lancement automatique (Main-Class spécifié dans le JAR
file) et voici les exceptions déclenchées :

java.io.FileNotFoundException:
C:\JavaProg\JobSearch\compiled\file:\C:\JavaProg\
JobSearch\compiled\test.jar!\com\test\Test3.xml (Le chemin d'accÞs spÚcifiÚ
est
introuvable)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown
Source)
at
sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown So
urce)
at java.net.URL.openStream(Unknown Source)
at org.apache.crimson.parser.InputEntity.init(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at
com.framework.controls.table.TableModelObject.setColumnsArray(TableMo
delObject.java:75)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject
.java:50)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject
.java:38)
at com.test.Test.<init>(Test.java:33)
at com.test.Test.main(Test.java:62)


Je ne comprends pas très bien pourquoi.
Je vais rechercher le fichier XML avec
maClasse.class.getResource(monFichier.xml);

La syntaxe est-elle correcte ? Dois je utiliser une autre instruction pour
aller rechercher mes datas dans un JAR file ?

Merci d'avance à tous pour remarques, suggestions, ....

Bernard

5 réponses

Avatar
Jean Bernard Root
maClasse.class.getResource(monFichier.xml);


heu vous ne mettriez pas "file:/cheminversmonfichier.xml" plutot ?

La bonne syntaxe pour accèder à un fichier de resource est de prendre le
haut du package comme racine.

maClasse.getClassLoader().getResourceAsStream ("/java/awt/awt.properties");

... il suffit qu'un jar contenant ce fichier à cet endroit soit dans le
classpath pour obtenir le stream.


La syntaxe est-elle correcte ? Dois je utiliser une autre instruction pour
aller rechercher mes datas dans un JAR file ?

Merci d'avance à tous pour remarques, suggestions, ....

Bernard




Avatar
Bernard Koninckx
Est-ce que la solution que tu me proposes est valable pour une application
non archivée ?

Merci

Bernard

"Jean Bernard Root" a écrit dans le message de
news: 4091199d$0$26994$
maClasse.class.getResource(monFichier.xml);


heu vous ne mettriez pas "file:/cheminversmonfichier.xml" plutot ?

La bonne syntaxe pour accèder à un fichier de resource est de prendre le
haut du package comme racine.

maClasse.getClassLoader().getResourceAsStream
("/java/awt/awt.properties");


... il suffit qu'un jar contenant ce fichier à cet endroit soit dans le
classpath pour obtenir le stream.


La syntaxe est-elle correcte ? Dois je utiliser une autre instruction
pour


aller rechercher mes datas dans un JAR file ?

Merci d'avance à tous pour remarques, suggestions, ....

Bernard






Avatar
Bernard Koninckx
Mintenant, l'erreur c'est transformée en :
java.io.FileNotFoundException:
c:JavaprogJobSearchsrccomframeworkcontrols
tableTableModelObject.dtd (Le fichier spÚcifiÚ est introuvable)
at org.apache.crimson.parser.Parser2.fatal(Unknown Source)
at org.apache.crimson.parser.Parser2.externalParameterEntity(Unknown
Source)
at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Unknown
Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at
com.framework.controls.table.TableModelObject.setColumnsArray(TableModelObje
ct.java:81)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject.java:5
2)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject.java:3
9)
at com.test.Test.<init>(Test.java:34)
at com.test.Test.main(Test.java:67)

Parce que je souhaite que mon XML soit validé sur base de la version de ma
DTD contenue dans le fichier JAR. Et je me suis déjà perdu pas mal avec les
packages XML. J'utilise DOM parce que mon fichier est de toute petite
taille. Cela ne demande pas d'utiliser SAX. Du moins je le pense.

Comment puis-je résoudre cette erreur ?

Bernard


"Bernard Koninckx" a écrit dans le message de
news: 40911746$0$21486$
Bonjour à tous,

J'ai essayé de mettre mes fichiers XML, DTD et classes de test dans un
fichier Jar avec lancement automatique (Main-Class spécifié dans le JAR
file) et voici les exceptions déclenchées :

java.io.FileNotFoundException:
C:JavaProgJobSearchcompiledfile:C:JavaProg
JobSearchcompiledtest.jar!comtestTest3.xml (Le chemin d'accÞs
spÚcifiÚ

est
introuvable)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown
Source)
at
sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown So
urce)
at java.net.URL.openStream(Unknown Source)
at org.apache.crimson.parser.InputEntity.init(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown
Source)

at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at
com.framework.controls.table.TableModelObject.setColumnsArray(TableMo
delObject.java:75)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject
.java:50)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject
.java:38)
at com.test.Test.<init>(Test.java:33)
at com.test.Test.main(Test.java:62)


Je ne comprends pas très bien pourquoi.
Je vais rechercher le fichier XML avec
maClasse.class.getResource(monFichier.xml);

La syntaxe est-elle correcte ? Dois je utiliser une autre instruction pour
aller rechercher mes datas dans un JAR file ?

Merci d'avance à tous pour remarques, suggestions, ....

Bernard




Avatar
jerome moliere
Bernard Koninckx wrote:
Bonjour à tous,

J'ai essayé de mettre mes fichiers XML, DTD et classes de test dans un
fichier Jar avec lancement automatique (Main-Class spécifié dans le JAR
file) et voici les exceptions déclenchées :

java.io.FileNotFoundException:
C:JavaProgJobSearchcompiledfile:C:JavaProg
JobSearchcompiledtest.jar!comtestTest3.xml (Le chemin d'accÞs spÚcifiÚ
est
introuvable)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown
Source)
at
sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown So
urce)
at java.net.URL.openStream(Unknown Source)
at org.apache.crimson.parser.InputEntity.init(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at
com.framework.controls.table.TableModelObject.setColumnsArray(TableMo
delObject.java:75)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject
.java:50)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject
.java:38)
at com.test.Test.<init>(Test.java:33)
at com.test.Test.main(Test.java:62)


Je ne comprends pas très bien pourquoi.
Je vais rechercher le fichier XML avec
maClasse.class.getResource(monFichier.xml);

getResourceAsStream() me semble plus adapté...


Jerome
--
Auteur cahier du programmeur Java tome 2 - Eyrolles 10/2003
http://www.eyrolles.com/php.informatique/Ouvrages/ouvrage.php3?ouv_ean13—82212111941

Avatar
Bernard Koninckx
Merci à tous,

getResourceAsStream était la bonne solution.
Je pensais que getResource était suffisant.

Quelle est la différence entre ces deux méthodes à part leur type de retour
?

Bernard


"Bernard Koninckx" a écrit dans le message de
news: 40911746$0$21486$
Bonjour à tous,

J'ai essayé de mettre mes fichiers XML, DTD et classes de test dans un
fichier Jar avec lancement automatique (Main-Class spécifié dans le JAR
file) et voici les exceptions déclenchées :

java.io.FileNotFoundException:
C:JavaProgJobSearchcompiledfile:C:JavaProg
JobSearchcompiledtest.jar!comtestTest3.xml (Le chemin d'accÞs
spÚcifiÚ

est
introuvable)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown
Source)
at
sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown So
urce)
at java.net.URL.openStream(Unknown Source)
at org.apache.crimson.parser.InputEntity.init(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown
Source)

at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at
com.framework.controls.table.TableModelObject.setColumnsArray(TableMo
delObject.java:75)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject
.java:50)
at
com.framework.controls.table.TableModelObject.<init>(TableModelObject
.java:38)
at com.test.Test.<init>(Test.java:33)
at com.test.Test.main(Test.java:62)


Je ne comprends pas très bien pourquoi.
Je vais rechercher le fichier XML avec
maClasse.class.getResource(monFichier.xml);

La syntaxe est-elle correcte ? Dois je utiliser une autre instruction pour
aller rechercher mes datas dans un JAR file ?

Merci d'avance à tous pour remarques, suggestions, ....

Bernard