help.! Java URLClassloader

Discussion in 'Java' started by Sundar, Nov 3, 2003.

  1. Sundar

    Sundar Guest

    I have a requirement, I have to use the existing jar of websphere,
    when my program is shipped. This program uses AdminClient of websphere
    JMX. This has to run as a standalone. It installs an application using
    JMX. What I require is to use URLCLassloader and load the adminclient,
    objectname classes and use them. If I set classpath i am working fine,
    but i do not have the luxury of that. Can I know how to use the
    URLClassLoader.

    A segment of my code looks like this.

    AdminClient client;
    Class createClass = loader.loadClass
    ("com.ibm.websphere.management.AdminClientFactory");

    Class[] args=new Class[]{java.util.Properties.class};
    Method create = createClass.getMethod("createAdminClient", args);
    Object params[] = new Object[]{props};
    Object obj= create.invoke((Object)"createAdminClient", params);
    //works fine till this
    client = (com.ibm.websphere.management.AdminClient)(obj); // casting
    no success error.

    String version = (client.getServerMBean()).getKeyProperty("version");
    // this is my purpose.

    Can anyone help me ? I am urgent schedule.

    Thanks in advance,
    sundar
     
    Sundar, Nov 3, 2003
    #1
    1. Advertising

  2. Sundar

    Anton Spaans Guest

    Your 'loader' variable needs to be a URLClassLoader instance:

    URL[] urlArray = ....;
    loader = new URLClassLoader(urlArray);

    Now the question is how to figure out the URLs in urlArray. I assume that
    your AdminClientFactory class is available locally (i.e. you could use the
    File object to get access to them), either in a directory on in a Java
    Archive (.jar, etc.. file).
    First, figure out the classpath you would have added if you had the luxury
    of that ( as you put it :) ). Each item in that classpath (be sure you have
    enough items to load your AdminClientFactory class and all the clasess it
    needs, etc..) can be represented by a File object. Take these as examples:
    "D:/MyProjects/ibm" for accessing
    "com.ibm.websphere.management.AdminClientFactory" and
    "D:/MyProjects/ibm/lib/ibm.jar" for the classes that are needed by it. Then:

    URL[] urlArray = new URL[] {
    new File("D:/MyProjects/ibm").toURL(),
    new File().toURL("D:/MyProjects/ibm/lib/ibm.jar")
    };


    That should do it.
    -- Anton.

    "Sundar" <> wrote in message
    news:...
    > I have a requirement, I have to use the existing jar of websphere,
    > when my program is shipped. This program uses AdminClient of websphere
    > JMX. This has to run as a standalone. It installs an application using
    > JMX. What I require is to use URLCLassloader and load the adminclient,
    > objectname classes and use them. If I set classpath i am working fine,
    > but i do not have the luxury of that. Can I know how to use the
    > URLClassLoader.
    >
    > A segment of my code looks like this.
    >
    > AdminClient client;
    > Class createClass = loader.loadClass
    > ("com.ibm.websphere.management.AdminClientFactory");
    >
    > Class[] args=new Class[]{java.util.Properties.class};
    > Method create = createClass.getMethod("createAdminClient", args);
    > Object params[] = new Object[]{props};
    > Object obj= create.invoke((Object)"createAdminClient", params);
    > //works fine till this
    > client = (com.ibm.websphere.management.AdminClient)(obj); // casting
    > no success error.
    >
    > String version = (client.getServerMBean()).getKeyProperty("version");
    > // this is my purpose.
    >
    > Can anyone help me ? I am urgent schedule.
    >
    > Thanks in advance,
    > sundar
     
    Anton Spaans, Nov 4, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. netpro2k
    Replies:
    2
    Views:
    1,103
    netpro2k
    Aug 21, 2003
  2. Cory
    Replies:
    13
    Views:
    5,777
    swick
    May 31, 2011
  3. Timothy Fosdike

    URLClassLoader slow in 1.4.2

    Timothy Fosdike, Aug 26, 2004, in forum: Java
    Replies:
    0
    Views:
    546
    Timothy Fosdike
    Aug 26, 2004
  4. Romain

    URLClassLoader and Tomcat

    Romain, Sep 28, 2005, in forum: Java
    Replies:
    2
    Views:
    4,540
    pkriens
    Sep 29, 2005
  5. iras

    applet and URLClassLoader

    iras, Aug 9, 2006, in forum: Java
    Replies:
    0
    Views:
    1,268
Loading...

Share This Page