I've got a situation where I'm trying to use the following java statement to find a class compiled by groovy and it's throwing a ClassNotFoundException:
Class findClass = Class.forName("tester.Rule_rule1);
Rule_rule1 is the class name of the groovy class that's been compiled to byte code and is sitting in the package named "tester".
If I use the same statement for a java source file that's been compiled and is under the "tester" package, it finds the class just find.
Any ideas? Thank you!
Dave Schick (SCJP 5.0, SCWCD)
posted 7 years ago
That should work. All Groovy classes can be treated exactly as Java classes.
Can you look in your output directory to ensure there is a Rule_rule1.class file in the tester package? If there is a class file there with the correct name, it doesn't matter whether Java or Groovy created it.
Of course, the Groovy jar must be present in the project classpath to load a Groovy class, but if you've got Groovy already in your project, it should be there.
Also, can you give more context to this issue and maybe a stacktrace? Tell us why you are loading a Groovy class from Java and maybe we can help you find a better way.