Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9128439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:30:50+00:00 2026-06-17T07:30:50+00:00

I have two URI objects. One is pointing to a folder in a JAR

  • 0

I have two URI objects. One is pointing to a folder in a JAR file, and another is pointing to a file in the same JAR file. The file is in a subfolder of the directory specified by the first URI. I like to create a relative URI so the resulting URI only containing the relative path to the file in the JAR.

  • Folder URI

    jar:file:/C:/Users/inagy/.m2/repository/hu/inagy/my-config-artifact/2.0-SNAPSHOT/my-config-artifact-2.0-SNAPSHOT.jar!/conf/
    
  • Resource URI

    jar:file:/C:/Users/inagy/.m2/repository/hu/inagy/my-config-artifact/2.0-SNAPSHOT/my-config-artifact-2.0-SNAPSHOT.jar!/conf/somesubpath/someconfig.xml
    
  • After calling folderUri.relativize(resourceURI) i’m expecting the following URI as a result:

    somesubpath/someconfig.xml
    

However i get resourceURI back which mean according to the URI class’s Javadoc that the JDK code find this two paths non relative to each other.

Is this a bug or i’m doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:30:52+00:00Added an answer on June 17, 2026 at 7:30 am

    I’ve been mildly annoyed by this too. The answer has nothing do to with the semantics of JAR files—it has to do with the syntax of jar: URIs. To be "relativized," a URI has to be hierarchical and not opaque. You will note from the JavaDoc for java.net.URI that:

    At the highest level a URI reference (hereinafter simply "URI") in string form has the syntax

    [scheme:]scheme-specific-part[#fragment]
    

    …

    An opaque URI is an absolute URI whose scheme-specific part does not begin with a slash character (‘/’). Opaque URIs are not subject to further parsing.

    …

    A hierarchical URI is subject to further parsing according to the syntax

    [scheme:][//authority][path][?query][#fragment]
    

    A JAR URI like jar:file:///home/me/foo.jar!/conf/ is parsed as:

    • scheme = jar
    • scheme-specific-part = file:///home/me/foo.jar!/conf/
    • fragment = (none)

    Because the scheme-specific-part does not begin with "/," it cannot be considered a hierarchical URI. The URI class does not treat jar: (or any) URIs specially, so it cannot recognize that the file:// part is a nested URI that is hierarchical.

    Since jar: URIs are opaque and not hierarchical, they are subject to the behavior documented for URI#relativize():

    The relativization of the given URI against this URI is computed as
    follows:

    1. If either this URI or the given URI are opaque, […], then the given URI is returned.

    EDIT: Left out a crucial part about opaque URIs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Uri objects passed into some code, one is a directory and
I have two panorama pages. The first one contains letters, the second one contains
i have one question regarding URI! i have two tables in my content provider!
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two classes (MVC view model) which inherits from one abstract base class.
I have two files client.php and server.php. The client file send a HTTP request
I have two columns say Main and Sub . (they can be of same
I have two XAML pages. One page (named Page1) has a listbox named strangers
I have multibinding on Image control. I bind two properties one is type of
I have a problem with two of my EventHandlers, they work the same, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.