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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:09:45+00:00 2026-06-18T18:09:45+00:00

What I am trying to do is to load .class file (compiled class file)

  • 0

What I am trying to do is to load .class file (compiled class file) from jar as a resource stream. This try is made from inside JUnit test case.

  1. test case compiles and runs without problem
    SO: AFAIK Asset class should be available in classpath
  2. full class name need to be consistent with its place in file structure
    SO: We can replace dots in package name with directory separator to get class file location
  3. We can access everything which is in current class path using getResourceAsStream method.

Let me present some code for better understanding.

package org.jboss.shrinkwrap.impl.nio.file;    
import org.jboss.shrinkwrap.api.asset.Asset;

public class FileStoreTestCase {
// (...)
@Test
public void usedSpace(){    
    final Class<?> classToAdd = Asset.class;
    final String pathToClass = new StringBuilder(classToAdd.getName().replace('.', File.separatorChar)).append(
            ".class").toString();

    final InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(pathToClass);

}

Problem is that in above code “in” variable is always null. Do you know why? And how I can get it to work?

Thanks for any input.

  • 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-18T18:09:47+00:00Added an answer on June 18, 2026 at 6:09 pm

    Try with replace(‘.’, ‘/’) i.e. use ‘/’ instead of File.separatorChar

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

Sidebar

Related Questions

I am trying to load some GZIP-ed data from a resource in my .jar,
I have been trying to load a resource dictionary XAML file in my view
In a controller class, I need to load a text file. I put this
I'm getting a cross domain error when trying to load a custom class. Here
I'm trying to load text of all divs that have a particular class into
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
Trying to load a small .txt file into mysql but get all my data
trying to load in a bunch of images into a list from a directory...my
I trying to load and save setting with this code but when I closing
i'm trying making a com dll in python. but i try register to compiled

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.