• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reflection

 
Hlias Makis
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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?
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • Mark post as helpful
  • send pies
  • 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.



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic