0

I'm uploaded my java ee online in a JBOSS server using openshift.

I'm trying to open an xml file with a servlet, (servlet location: src/main/java/myservlet/myservlet.java) I can access to my servlet if I try in web naviguator/java client with html output. My xml file is in src/main/resources/Liste.xml

I found in stackoverflow that I must use this with maven for deployment:

InputStream is = ClassName.class.getResourceAsStream("/Liste.xml");

But in my constructor I do this to parse my xml file:

    File fichier = new File(nomFichier);
    document = constructeur.parse(fichier);

So I don't really understand how to use getResourceAsStream...

user1904731
  • 91
  • 1
  • 11

1 Answers1

0

This method will search in the local classpath, in the jar and in the directory where the class file was loaded. If the file path starts with /, it's an absolute path otherwise the file path is relatif to the package of your class (ClassName in your case). You can take a look at the following post: how do you make getResourceAsStream work while debugging Java in Eclipse?

Community
  • 1
  • 1
David Mangon
  • 150
  • 1
  • 2
  • 10