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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:12:31+00:00 2026-06-14T16:12:31+00:00

I am currently trying to generate code on the fly, compile it then run

  • 0

I am currently trying to generate code on the fly, compile it then run it as a JUnit4 test. I am quite close to the goal, but I have an issue which might be either with plexus-compiler-eclipse or how I load the compiled class. Let me explain:

  1. I write to a file the java code using a simple FileWriterWithEncoding
  2. I compile it as Java6 code (source-target-compliance) using plexus-compiler-eclipse (also tried with plexus-compiler-javac) using EclipseJavaCompiler().performCompile(CompilerConfiguration)
  3. I load the class using URLClassLoader.newInstance(new URL[] {resource }).loadClass("classname") where resource is getClass().getResource("filename") (also tried with getClass().forName(className, true, classLoader) where the classLoader is the same URLClassLoader as above)
  4. Then I use an instance of JUnitCore to run my generated test class using JUnitCore().run(result of loading the class above)

Everything seems fine until point 4, where JUnit does not see any test method on the class (I obviously did annotate with @org.junit.Test each test method in the generated code). Debugging, I can see that if I do a newInstance() on the loaded class or inspect the loaded class, I have no annotations, no public methods, no declared fields, SFA!!! The newInstance() only has a private member, which is normal, since its reference type is Object, but somehow I am not able to cast it to try calling the public methods that should be there.

Any idea what I am missing in my compilation/class loading that makes the runtime class incomplete?

Thanks in advance for any ideas…

  • 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-14T16:12:32+00:00Added an answer on June 14, 2026 at 4:12 pm

    Apparently, this was pretty simple! I found this answer that made me aware that my URLClassLoader was missing a parent.

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

Sidebar

Related Questions

I am trying to generate a hierarchical directory listing in pyGTK. Currently, I have
I am trying to make some optimized code using SSE2 instructions. Currently, i have
Im trying to generate a color gradient using ColdFusion. My current code below works
I am currently trying to generate the creation SQL for my tables based off
currently i'm trying to use imagick to generate some images without saving them on
I am currently trying to write some code that will accept some FTP details,
I'm trying to generate some LaTeX code which from thereon should generate PDF documents.
I am currently trying to generate colored results after a search containing keywords. My
I am trying to generate C# code from an XSD using xsd.exe Here is
I'm currently trying to style up a Wordpress theme, I don't have the greatest

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.