• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reflection

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i hava a java program that uses an external tool that reads a wsdl and generates some java files and .class.
then i want to use reflection to this files and call some methods but i get class not found exception is there a way to solve this problem??
i read something about setting the classpath through java but i did't understand much
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, you have a tool that generates Java source files? You'll have to compile those source files first, and then make sure the compiled classes are in the classpath, before you can use reflection on those classes.

Did you compile the generated source files?
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without importing them, you could use Class.forName(String className) to create an instance of the Class
and do your reflection for there.

The .classes will still have to be on the CLASSPATH, but this approach offers a lot of flexibility.

WP
 
Hlias Makis
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I compiled those classes but I dont know how to put them dynimically to my,classpath.i use class.forname and I get class not found exception
 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course it would not harm in the first place to double check whether those classes really appear at the right location in the classpath.

I must admit how the normal class loading works, that is, whether this scenario works:
1) the program starts against a given classpath
2.1) it lets either java files generated and compiles them and puts them on the classpath
2.b) or it lets Java class files generated and puts them on the classpath
3) the program can access the generated classes and use them with, say, forName or reflection.

If the Java runtime scans the class path at starting time to make a list of the available classes, then putting there additional ones later won't help. I do not know, I must admit. In this case maybe a custom class loader can help.



 
You don't like waffles? Well, do you like this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic