Problem while retrieving XSL in JAR with getResourceAsStream

Hello everyone,

My problem is that I'm trying to load XSL files from a JAR (and obviously does not succeed ;-))

I implemented a URIResolver. This resolver gives me the names of the files as specified in the "xsl:include".

Problem : the xsl:include in my stylesheets contains relative path like "/myDirectory/../directory/another.xsl".

When I execute : "class.getResourceAsStream(/myDirectory/../directory/another.xsl)" it returns null when I have the JAR file in the classpath but returns a valid InputStream when I reference the directory in the classpath.

The '/../' in the path does not seem to work when retrieving a resource from a JAR file... Is this a bug or am I missing something?

To validate this, I tried the following :

class.getResourceAsStream("/myDirectory/directory/myXSL.xsl") which works.

Now I tried this :

class.getResourceAsStream("/myDirectory/directory/../directory/myXSL.xsl") which DOES NOT WORK.

Thansk in advance,

J閞鬽e.

[1024 byte] By [MrJejea] at [2007-10-3 11:47:06]
# 1
getResourceAsStream doesn't take a directory path as an argument. It is a resource path relative to the classpath roots, and there's no such thing as ".." (parent directory) indicators in such paths.
warnerjaa at 2007-7-15 14:20:01 > top of Java-index,Java Essentials,Java Programming...
# 2

Let's take an example, I have the following file system :

sourceDir

| --> myDirectory

|--> myFile.xsl

If I search for myDirectory/../myDirectory/myFile.xsl when the "sourceDir" is in the classpath, it works. However when it is in a jar file, it does not.

Why such a difference ? Why can't the file be found when in a JAR ?

Thanks in advance,

J閞鬽e.

MrJejea at 2007-7-15 14:20:01 > top of Java-index,Java Essentials,Java Programming...
# 3
Are you claiming getResourceAsStream works when not in a JAR, with paths containing ".." ? I don't think so.
warnerjaa at 2007-7-15 14:20:01 > top of Java-index,Java Essentials,Java Programming...
# 4

In fact, yes I do.

I'm under Eclipse and executing the expression in the debug perspective. The parent directory containing my resources are in the classpath for my test.

When I replace this directory by the corresponding jar, it does not.

According to you, it should not work but I wonder why? ".." can be a part of a relative path ?

MrJejea at 2007-7-15 14:20:01 > top of Java-index,Java Essentials,Java Programming...