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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:15:57+00:00 2026-06-15T23:15:57+00:00

Please, imagine a folder which has two files MyApp.jar B.class (real path is long)

  • 0

Please, imagine a folder which has two files

  1. MyApp.jar
  2. B.class (real path is long)

Inside the jar there is some code to check whether B.class exists inside jar-file.

try {
    Class.forName("B");
    System.out.println("exists");
} catch (Exception ignored) {
    System.out.println("does not exist");
}

But even though B.class is not inside jar, the code above does not throw exception, because B.class exists outside of jar.

The jar is generated with Ant from Eclipse. So I thought class-path might be the reason

 <manifest>
     <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
     <attribute name="Rsrc-Main-Class" value="org.client.Client"/>
     <attribute name="Class-Path" value="."/>
     <attribute name="Rsrc-Class-Path" value="./ many_jar_here.jar"/>
  </manifest>

So I have changed only Class-Path like this

<attribute name="Class-Path" value=""/>

But now it gives an error like this:

 Exception in thread "main" java.lang.NoClassDefFoundError: B
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRs
der.java:56)
Caused by: java.lang.ClassNotFoundException: B
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        ... 3 more
  • 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-15T23:15:58+00:00Added an answer on June 15, 2026 at 11:15 pm

    In this scenario, where B is found by the class loader but it’s not in the jar, you could additionally check if

    B.class.getProtectionDomain().getCodeSource() == ClassKnownToBeInJar.class.getProtectionDomain().getCodeSource()
    

    or

    B.class.getProtectionDomain().getCodeSource().getLocation().getPath().contains("MyApp.jar")
    

    If either of those is true, B was loaded from MyApp.jar.

    So, something like this:

    try {
        Class bClass = Class.forName("B");
        System.out.println("exists");
        if (bClass.getProtectionDomain().getCodeSource().getLocation().getPath().contains("MyApp.jar")) {
            System.out.println("class loaded from MyApp.jar");
        } else {
            System.out.println("class not loaded from MyApp.jar");
        }
    } catch (Exception ignored) {
        System.out.println("does not exist");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello (please excuse me for my ugly english :p), Imagine these two simple models
Let's imagine this simple, I have a div (myDiv) inside a form which includes
PHP's DateTime class has the two methods add() and sub() to add or subtract
I have a server which feeds several applications. Please imagine that I'm a user
Imagine I have a static class and a static method inside that. And it
Imagine I have a long, multi-word line of text in a DIV: Hello there,
Please imagine this small database... Diagram removed dead ImageShack link - volunteer database diagram
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
Please let me know what are default locations for Downloads folder on devices with
So imagine this scenario, I have a list and it has a bit of

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.