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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:32:41+00:00 2026-06-15T05:32:41+00:00

This should be simple but it has cost me hours. Everything I find on

  • 0

This should be simple but it has cost me hours. Everything I find on this site indicates I am doing it right but the file still cannot be found.

Inside a jar file I have two files ‘CDAkeystore.jks’ and ‘CDAtruststore.jks’ at top level.
Yet when I call
securityProps.setProperty("javax.net.ssl.keyStore","CDAkeystore.jks");
I get a system cannot find the file requested error.
The class file calling this method is inside the same jar in the usual package arrangement.

The jar file is as follows:

com ..... (a lot more class files)
org ..... (lots of class files)
META-INF
CDAtruststore.jks
CDAkeystore.jks

How can this be SOOO difficult?!!

———- Added INfo ——n

Since the object using the path is open source I found the routine they are using to load the file. It is:

InputStream keystoreInputStream = preBufferInputStream(new FileInputStream(keyStoreName));

which according to the documentation of FileInputStream(String name) is

Creates a FileInputStream by opening a connection to an actual file, the file named by the path name ‘name’ in the file system. So how should this path be expressed?

  • 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-15T05:32:42+00:00Added an answer on June 15, 2026 at 5:32 am

    The answer is, in short, that you can’t. At least in this situation. I am stuck with passing a path to a file to a library implementation that I have no control over. So the library method accesses the file on the assumption that the file exists in unzipped form in the OS’s file system. It is getting the path from a Property.setProperty(stringKey, stringPath)
    So the only solution I found was an ugly hack. I need to take the resource in my jar and copy it to a file on the system. Then I would pass the path to that file in the above setProperty() method. The ugly hack is implemented as follows (if anyone else can come up with a nicer solution I would be happy). It does solve the problem. The library routine is able to find my newly created file.

    /* This evil reads a file as a resource inside a jar and dumps the file where ever
     * the loader of this jar/application defines as the current directory. This pain is done
     * so the SecurityDomian class can load the file; it cannot access the file from
     * the jar. This means the 'name' passed in contains the file name inside the jar
     * prefixed with "/" so it is not read with an assumed package extension.
     */
    private boolean createFileFromResource(String name)
    {
        // Dont bother if the file already exists
        if(new File(name.replace("/", "")).exists())
        { 
            return true;
        }
        byte[] keystoreFile = new byte[2048];
        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(2048);
        // Get the resource
        InputStream inputStream = this.getClass().getResourceAsStream(name);
        try
        {
            int bytesRead = 0;
            while(true)
            {
                // Read the resource into the buffer keystoreFile in 2048 byte chunks
                bytesRead = inputStream.read(keystoreFile);
                if(bytesRead < 0)
                {
                    break;
                }
                // Copy and append the chunks to the ByteArrayOutputStream (this class
                // does the auto-extending of the output array as more chunks are 
                // added so you don't have to do it.
                byteArrayOut.write(keystoreFile, 0, bytesRead);
            }
            inputStream.close();
            // Now create a file at the root of where ever the loader happens to think
            // the root is. So remove the "/" in front of the file name
            FileOutputStream outputStream = new FileOutputStream(name.replace("/", ""));
            // Write out the file. Note you will be left with garbage at that location.
            byteArrayOut.writeTo(outputStream);
            outputStream.flush();
            outputStream.close();
        } 
        catch (IOException e)
        {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(This should be simple. But it has been driving me nuts for many hours.)
This task should be quite simple, but nothing I tried has worked. I'm just
This should be simple task but i am not been able to find the
This should be simple, but I am still lost. There is a very similar
this should be a simple question, but the answer has eluded me for some
This should be simple to do, but I can't seem to find any documentation
OK, so this should be simple... But I still can't figure it out. I
This should be simple but I cannot find the answer anywhere. On our asp.net
Ok This should be a simple task but it has been sending me insane.
I think this should be simple but I am having some difficulty implementing it.

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.