Ivocation II

Hi,
Strange things happen with this invocation trickery.
I've class-loading related problem.
I have class file (Exec.class) and list of libraries (jars) it uses.
In my code (Invoke.java), I first, use URLClassLoader to create instance of Exec class and load all required jars. As second step I invoke exec() method of instance of Exec.
Exec uses xerces.jar, so when I load its instance, I specify xerces.jar as one of URLs passed to URLClassLoader. Getting instance works OK. When I invoke Exec's instance than, Exec throws error java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser which is saying, that it can't find class from xerces.jar file. If xerces wasn't loaded, first step would fail and would not let me proceed to invocation.
Interesting thing is, that I tried to run Invoke with -cp xerces.jar and invocation run ok.
As Exec.class can request any library it wants, it can't be solved by putting all needed jar files on command-line.
As a deed of desperation, I tried changing System property "java.class.path" on runtime, so that it contained xerces.jar but it didn't help either.
To me it seems that loaded libraries for some reason don't propagate to invoked class. Seems bizzare.
Any help ?
Michal

OK. To make things clear I describe my situation.
I have Invoke class which gets name of class to invoke and libraries it depends on. (Simplified) code of Invoke may look like this:Invoke.java:
public class Invoke{
    String classToInvoke = "Exec.class"
    String method = "exec"
    String library = "xerces.jar"
    public static void main(String []args){
        Object newInstance = loadExternalClass(classToInvoke,library);
        invokeClass(newInstance,method);
    public Object loadExternalClass(String classToInvoke,String library){
        URL[] urlsToLoad = new URL[]{
            new File(classToInvoke).toURL(),
            new File(library).toURL()
        URLClassLoader urlClassLoader = new URLClassLoader(urlsToLoad);
        Class newClass = urlClassLoader.loadClass()
        return newClass.newInstance();
    public void invokeClass(Object instanceToInvoke,String methodToCall){
        Method execMethod = ... // getting right method from instanceToInvoke
        execMethod.invoke(instanceToInvoke,invokeParameters);
}And Exec.class would look like:
import org.xml.sax.*;
public class Exec {
    public void exec(){
         // \/\/\/\/ here it fails
         XMLReader reader = XMLReaderFactory.createXMLReader ("org.apache.xerces.parsers.SAXParser");
        reader.setContentHandler(this);
        InputSource inputSource = new InputSource(new StringReader(xml));
        reader.parse(inputSource);
}Exec.class doesn't use reflection. (and isn't aware, there is any reflection business going on)
Concerning hierarchy of ClassLoaders. I know that you may pass reference to parentClassLoader when you create a new one, but never investigated why you would like to do it (I suppose, it's called when local ClassLoader doesn't succeed to find class it is ordered to load).
Thus I don't know what is implication of such a hierarchy and have no clue what to do to have my code working.
Any advice appreciated.
Michal

Similar Messages

  • How toAccess User Defined Properties in NWDS

    Hi to Experts,
    i hope some one might faced this same problem, i want access user defined properties from KM to NWDS. For that Iu2019m using
    EP 7.0 and NWDS Version: 7.0.11.
    i have one Req.. to send value as a text or String to Km Property for store or display Km Folder. Like as we have name, date, created by, Description, Extra..... at the same place i want create my own Properties(using with Property metadata @ Global Service) and what ever Properties i created those ones i want use and store or send date to that particular property to display to end-user.
    For above process am using WDJ
    hope i can get this And thanQ in Advance.
    vita

    - Create a user-defined OTD with one String field.
    - Create an XSD-based OTD with repeating name and value fields of type String
    - Create a "New Web Service" Java Collaboration whose input will be the first OTD, whose output will be the second OTD and whose operation will be named getProeprties, or some such
    - Implement, in Java, the code necessary to read your properties, given the properties file name or path (given in the input OTD) and populate the name/valur pairs on the output OTD
    - drag the operation of the collaboration onto the Business Process Editor canvas as an Activity
    - Configure a Busienss Rule to set the input of the getProperties activity to the name/path of the properties file
    - Configure a Business Rule(s) to use the name/value pairs returned from the ivocation of teh getProperties service
    If you wish to take this one step further you could consider writing the java collaboration
    a) generically so it can be reused from different business processes
    b) to cache the properties on first read so each invocation after the first one simply returns the in-memory values instead of re-reading the proerties from disk
    c) generically so it can read, cache and return different property sets depending on the properties file/path provided as input.
    Bear in mind that IO from a java collaboration by means other than an eWay violates the EJB spec.. It works all the same.
    Message was edited by:
    mczapski

  • How to export user defined properties in seperate file

    Hello,
    i want to export user definied properties in a seperate file using OMB+ commands. The documentation of this topic doesn't work.
    The OMB Code I use is the following:
    OMBEXPORT TO MDL_FILE '${Pfad}/006_${Project}.mdl' \
    FROM PROJECT '${Project}' \
    ALL_CLASS_DEFINITONS \
    CONTROL_FILE '$SANDBOX_HOME/Project.ctl' \
    INCLUDE_USER_DEFINITIONS \
    OUTPUT LOG TO '${Pfad}/006_${Project}_exp.log'
    The control file defines the path and filename for the the definitons in this way:
    DEFINITIONFILE=C:\Arbeitsverzeichnis\udp.mdd
    But the file will not be created and i get no error message.
    When using this command the udp' definitons will be exported, but in the general project export file. Which is the correct way to export the definition in a seperate file?

    - Create a user-defined OTD with one String field.
    - Create an XSD-based OTD with repeating name and value fields of type String
    - Create a "New Web Service" Java Collaboration whose input will be the first OTD, whose output will be the second OTD and whose operation will be named getProeprties, or some such
    - Implement, in Java, the code necessary to read your properties, given the properties file name or path (given in the input OTD) and populate the name/valur pairs on the output OTD
    - drag the operation of the collaboration onto the Business Process Editor canvas as an Activity
    - Configure a Busienss Rule to set the input of the getProperties activity to the name/path of the properties file
    - Configure a Business Rule(s) to use the name/value pairs returned from the ivocation of teh getProperties service
    If you wish to take this one step further you could consider writing the java collaboration
    a) generically so it can be reused from different business processes
    b) to cache the properties on first read so each invocation after the first one simply returns the in-memory values instead of re-reading the proerties from disk
    c) generically so it can read, cache and return different property sets depending on the properties file/path provided as input.
    Bear in mind that IO from a java collaboration by means other than an eWay violates the EJB spec.. It works all the same.
    Message was edited by:
    mczapski

Maybe you are looking for

  • Monitor compatibility issue syncmaster

    To whom it may concern, I have the following problem with my Macbook. I used to use my Samsung Syncmaster 2243BW monitor as an extra display connected to my macbook. It used to work fine with Leopard 10.5, but since the SnowLeopard came out it doesn'

  • Filename for ImageIcon

    Hi all How to avoid hard coding the absolute path for the argument for ImageIcon ? For example : ImageIcon icon = new ImageIcon("c:\\img\\help.gif"); Thank you

  • Calculating over time

    Hi I am making up a time sheet calculator (example below), and need help figuring out how to calculate overtime. I figured out how to calculate total time for the day ( SUM=(B2-A2)+(D2-C2) ) and calculating over time is simple if the total time is gr

  • Return Code value using 'starting new task' and 'wait until'

    I'm having a minor issue with some return code values in my ABAP. This is what part of it used to look like before I modified it: With Code in version 1, the sy-subrc was not always zero, sometimes it would be 4. That was fine, and my abap would do s

  • Anyone have trouble with ULN 4.5 ISOs?

    I've never had a problem with downloading, burning, and using ISOs, until now... I don't claim to be an expert, but I've been around the farm a while. I downloaded the 4.5 installation (zipped) ISOs, 4 of them. I checked the md5sums on the zip files