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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:03:26+00:00 2026-06-13T03:03:26+00:00

ClassNotFound (yes, I know, there are lots of posts about this exception; I searched

  • 0

ClassNotFound (yes, I know, there are lots of posts about this exception; I searched here and elsewhere and could not find an explanation)

Why does Class.forName fail?

groovy> class Foo { 
groovy> } 
groovy> def f = new Foo() 
groovy> def cname = f.getClass().getName() 
groovy> def p = f.getClass().getPackage() 
groovy> def l = f.getClass().getClassLoader() 
groovy> println "Foo class name: $cname" 
groovy> println "Foo package: $p" 
groovy> println "Foo class loader: ${f.getClass().getClassLoader().toString()}" 
groovy> println "Current class loader: ${this.getClass().getClassLoader().toString()}" 
groovy> try { 
groovy>     Class.forName(cname) 
groovy> } catch (Exception e) { 
groovy>     println e 
groovy> } 
groovy> l.findClass("Foo") 



Foo class name: Foo
Foo package: null
Foo class loader: groovy.lang.GroovyClassLoader$InnerLoader@2d275595
Current class loader: groovy.lang.GroovyClassLoader$InnerLoader@2d275595
java.lang.ClassNotFoundException: Foo
Exception thrown
Oct 16, 2012 4:43:28 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize
WARNING: Sanitizing stacktrace:
java.lang.ClassNotFoundException: Foo

Thanks!

  • 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-13T03:03:27+00:00Added an answer on June 13, 2026 at 3:03 am

    This is due to the ClassLoader. The ClassLoader inside the the shell (ie the classes you define inside the shell) is different from the ClassLoader that runs the shell (the jars that you need to run the shell). That is why, the command Class.forName("Foo", true, this.class.classLoader) works, because you specify the ClassLoader inside the shell

    try

    def shell=new GroovyShell()
    
    def f=shell.evaluate("class Foo{Foo(){println this.class.classLoader}};def f=new Foo()")
    
    println shell.class.classLoader
    shell.evaluate("println this.class.classLoader")
    
    println "-----------"
    println Class.forName("Foo", true, f.class.classLoader)
    println Class.forName("Foo", true, this.class.classLoader)
    

    You will see that the first Class.forName works, not the second. running the script is similar because it will create a script class that does not share the shell’s ClassLoader

    Doing Class.forName won’t use the same this as this in the context of your script.

    Not sure it is clear enough 🙁

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

Sidebar

Related Questions

I'm getting on the very first call to my facelet a classnotfound exception. On
I am asking this here in the hope that someone has maybe come across
There are two assemblies: 1) Assembly containing serializer. This is a place from where
Possible Duplicate: ClassnotFound exception using java reflection I get exception, java.lang.ClassNotFoundException: SavingAccount , while
I'm suddenly unable to run my app due to this error, where the ClassNotFound
hi im trying to use apatche 4.0.1 using the post methode in this example
I have my own exception handler: module Frog module Errors class NotFound < FrogError
I have a very large workspace with about 30 projects all together. I am
a fews days ago, i tried to learn the python twisted.. and this is
I have a folder organization that looks like this: link.sh dist/MyApp-3.0.0/script.sh dist/MyApp-3.0.0/lib/*.jar The link.sh

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.