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

  • Home
  • SEARCH
  • 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 6628931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:11:16+00:00 2026-05-25T22:11:16+00:00

I have a class names test.java and another file log4j.properties in the same folder

  • 0

I have a class names test.java and another file “log4j.properties” in the same folder but following call

getClass().getResource("log4j.properties")

fails with

ms
Trace:
sun.misc.InvalidJarIndexException: Invalid index
    at sun.misc.URLClassPath$JarLoader.getResource(Unknown Source)
    at sun.misc.URLClassPath$JarLoader.getResource(Unknown Source)
    at sun.misc.URLClassPath$JarLoader.findResource(Unknown Source)
    at sun.misc.URLClassPath.findResource(Unknown Source)
    at java.net.URLClassLoader$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findResource(Unknown Source)
    at java.lang.ClassLoader.getResource(Unknown Source)
    at java.lang.ClassLoader.getResource(Unknown Source)
    at java.lang.Class.getResource(Unknown Source)

But getClass().getClassLoader().getResource(“log4j.properties”) works. What can be the reason?

  • 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-05-25T22:11:17+00:00Added an answer on May 25, 2026 at 10:11 pm

    The InvalidJarIndexException is normally caused by a corrupt INDEX.LIST file in the JAR. So check the JAR for any problems. See http://littletechsecrets.wordpress.com/2008/12/01/why-does-invalidjarindexexception-occur/

    The different results you describe are probably related to Class.getResource() resolving a path relative to the classes package, and ClassLoader.getResource() resolving a path relative to the root. So getClass().getResource("/log4j.properties") might fix your problem.

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

Sidebar

Related Questions

I have Java classes with the following structure (the class names do not imply
I have got the following code in a file called test.java which is located
I have the following code (changed object names, so syntax/spelling errors ignore). public class
I have the following classes: package models; public class Test extends activejdbc.Model { }
I have to test few sites which sales the same things, but they have
i have class named Group i tried to test configuration: var cfg = new
Say I have a Metal class named Preview. How do I test it with
I have a simple class I'm serializing. [DataContract(Name = Test, Namespace = )] public
If I have class names such as left, right, clear and xhtml like <a
I have a class named baseClass. From this class I inherit a class names

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.