This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "reflection" Watch "reflection" New topic
Author

reflection

Hlias Makis
Greenhorn

Joined: May 21, 2012
Posts: 10
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

Joined: Aug 16, 2005
Posts: 14117
    
  16

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?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

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

Joined: May 21, 2012
Posts: 10
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

Joined: May 22, 2012
Posts: 867
    
    5
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.



 
 
subject: reflection