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 7973391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:05:15+00:00 2026-06-04T08:05:15+00:00

My problem is the following: I am trying to access a class file in

  • 0

My problem is the following:
I am trying to access a class file in a Jar.
I have a jar “dumb.jar” located in package “com.msgxsd”. The jar is on the classpath, and If I try and do

InputStream is = this.getClass().getClassLoader()
            .getResourceAsStream("com/msgxsd/dumb.jar");

then I get an input stream for the jar without a problem.

The problem arises when I try and get an input stream (or a URL) for the file inside the jar. All the jar contains (apart from the manifest obviously) is the file “DummyClass1.class”.

I have tried all of the following:

InputStream is = this.getClass().getClassLoader()
.getResourceAsStream("DummyClass1.class");

InputStream is = this.getClass().getClassLoader()
.getResourceAsStream("dumb.jar!/DummyClass1.class");

But the input stream returned is always null. I have also tried

URL url = this.getClass().getResource("DummyClass1.class");
URL url = this.getClass().getResource("dumb.jar!/DummyClass1.class");

But the URL returned is null.

I have already looked at every single one of the questions relating to accessing a file within a Jar, but the proposed solutions (as seen above) do not work for me.

All I want is to be able to get either an InputStream (or ideally a URL) for the “DummyClass1.class” inside the jar, so that I can the somehow construct a File instance.

Any suggestions would be much appreciated.

  • 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-04T08:05:17+00:00Added an answer on June 4, 2026 at 8:05 am

    Try this (sorry if there are typos, I’m just typing the code off the top of my head without trying it):

    int index = path.indexOf('!');
    if (index == -1) return url.openStream();
    String jarPath = path.substring(0, index);
    File jarFile = new File(new URL(jarPath).toURI());
    
    if (!jarFile.exists()) return null;
    
    String filePath = path.substring(index + 1);
    if (filePath.startsWith("/")) {
        filePath = filePath.substring(1);
    }
    
    JarFile jar = new JarFile(jarFile);
    return jar.getInputStream(jar.getJarEntry(filePath));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to solve the following problem. Lets say you have the the
Trying to use JSTL but have the following problem: Index.xhtml page: <?xml version=1.0 encoding=UTF-8?>
I am trying to write a shell script to simulate the following problem: File
I'm a newbie in bash scripts and have the following problem : I'm trying
I have a bit of a problem. I am trying to do the following
I get the following problem when trying to open an ASPX page in FireFox:
I am trying to make a chatroom layout like the following: Now my problem
The following markup is exaggerated to demonstrate the problem. I'm trying to capture the
I have the following problems: First: I am trying to do a 32-spaces bitwise
I have the following code in controllers/list.php: <?php class List extends Controller { function

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.