How to load classes dynamically?

Hi all!
I have folowing problem.
In my applet I need to load different classes form the same Web server. The main class is located in parent directory and different are in it's subdirectories. Security Manager allows to do this, but I find it difficult how to do it. Can you give me advise how to do it.
Thanks beforehand...

Create a package on the web side myserver.mypackage with subfolders ex1 ex2
THere place your class files to dynamical loading
Every class in package must starts from
package myserver.mypackage; statment
In paren directory for package creat a class where main applet class will be located
Create an inctance for submain classes as
(Class)Class.forName("myserver.mypackage.ex1.Class1").newInctance() - for class1 in ex1
(Class)Class.forName("myserver.mypackage.ex2.Class1").newInctance() - for class1 in ex2
It works. I'll send you example on e-mail.

Similar Messages

  • How to load classes at ejb module deployment

    Hi,
    Can someone tell me how to loaded a class when I deploy an ear module (the class is in the ear) ?
    Thanks in advance.
    Fred.

    Hi Fred,
    Can you explain your question a bit more? Are you asking how to do
    dynamic class loading for your application or just how to package
    classes appropriately?
    --ken                                                                                                                                                                                                                                                                                                                                                               

  • How to load classes other than stub classes required for the stub classes

    Can any one pls tell me how to load supporting classes and interfaces for the stubs thru RMI? I am copying necessary stubs and policy file in the client class.
    one of the method of the class returns another supporting class. whenever i invoke this method ot says Class NotFoundException. I dont want to copy these supporitng classes into my client. They are deployment issues involved with this.
    HOW CAN I LOAD THE CLEINT CLASSES THRU RMI

    You should look at the documentation concerning CODEBASE. -Djava.rmi.server.codebase=
    It is too involved to explain it all here.

  • How to Load Classes in run time - Urgent

    Hi All,
    How to Load a class file from a .jar file in JDK1.1 with out using URLClassLoader. I have tried to extract the .jar file by file input stream and zipEntry classes and defineClass using the bytes i got from the stream , but the class loader fails to take the classes that are already loaded in the system.
    The customClassLoader that i created was not able to assign an object to the another reference variable that already in the JVM.Please i want to know how to assign or communicate between the objects of CustomclassLoader and SystemClassLoader?
    Please help me in this regard.
    Thanks in advance,

    Hi,
    The above code works in the straight way if the class is available in the classpath.
    I need to load a class by using custom class loader that i extends from classloader base class .
    I have to read a class file from a .jar file (in server) and load it in run time.Here i am able to read the bytes from the .jar file of the specified class file, but the class that i read extends some other class that is already loaded when i tried to create newInstance of the class i get Exceptions. Here the custom classLoader cannot find the loaded existing class in the JVM.can i get a solution for this situation

  • How to instanciate Class Dynamically

    I need to create instance and use class dynamically.
    Suppose the codes instantiating an Object weather:
    Weather weather=new Weather();but i want to do it dynamically, where the class name will be given as a String variable
    in this case i will have
    String className="Weather";then i want to replace the above Weather weather=new Weather(); to something like as:
    Class.forName(className) instanceName=new Class.forName(className)() or somehow.
    is it possible? Thank you for spending time to read my post.

    Loading a Class by name and then creating an instance is easy enough. But because Java is a compiled language you can't just create a variable of a type unknown at compile time. The compiler needs to know what fields and methods are available up front, before any classes get dynamically loaded.
    If you know the class you are going to load will be some subclass of "Weather", of if Weather is an interface and the class implements it, then you can create an instance and cast it to type Weather, then use the methods and fields of weather on it. If you don't have such information about the class you're going to load you need to access any objects created using reflection.

  • How to load code dynamically?

    I want to design a system with plugin capability.
    How can I do it?
    How to load code from OBJ or Library dynamically?
    thx

    It sounds like you are looking for dynamic linking
    functionality. (dlopen(), dlclose(), dlsym(), etc).
    The functionality is pretty well documented along with some
    sample code in the Linker and Libraries Guide. Here is a link
    to the relevant page on docs.sun.com:
    http://docs.sun.com:80/ab2/coll.45.13/LLM/@Ab2PageView/4817?Ab2Lang=C&Ab2Enc=iso-8859-1

  • How to load class from jar file dynamically?

    After I run my Java applicatoin, I need configuring the classpath of jvm to load some classess inside a jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know where the jar file is, what the jar file name is. All depends on the user to tell the jvm the details through some UI. I've tried to write: System.setProperty("java.class.path", "c:\myClass.jar");Class.forName("MyClass"); but failed.
    Can you tell my why and how?
    Thx

    After I run my Java applicatoin, I need configuring
    the classpath of jvm to load some classess inside a
    jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know
    where the jar file is, what the jar file name is. All
    depends on the user to tell the jvm the details
    through some UI. I've tried to write:
    System.setProperty("java.class.path",
    "c:\myClass.jar");Class.forName("MyClass"); but
    failed.That won't work. By the time it gets to your code it already has a copy of the original. You can't change it (short of modifying the JVM.)
    Can you tell my why and how?The usual way is to use a custom classloader.
    You can start by looking at java.net.URLClassLoader.

  • How  to load  class ???

    please note the below code :
    String systemPath = System.getProperty("java.class.path");
    String classpath = "E:\\Test.jar;" + systemPath;
    System.setProperty("java.class.path",classpath);
    System.out.println("class-path: " + getCompilerClassPath());
    Class.forName("Test");
    Why I can't load the Test class ?? please help me !
    thanks!

    After I run my Java applicatoin, I need configuring
    the classpath of jvm to load some classess inside a
    jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know
    where the jar file is, what the jar file name is. All
    depends on the user to tell the jvm the details
    through some UI. I've tried to write:
    System.setProperty("java.class.path",
    "c:\myClass.jar");Class.forName("MyClass"); but
    failed.That won't work. By the time it gets to your code it already has a copy of the original. You can't change it (short of modifying the JVM.)
    Can you tell my why and how?The usual way is to use a custom classloader.
    You can start by looking at java.net.URLClassLoader.

  • How to load Class only once...

    hi all,
    i am using the Class.forName() to load the class.
    the code looks like as follows :
    for loop.....{
    Class.forName("classA");
    inside the for loop , is there any possiblity of knowing that the class is already loaded or not. i can load the class the outside the for loop . but i am curious to know how we can check whether the classA is already loaded or not for the next iteration of the loop.
    tia,
    dhanasekaran.

    Class.forName() will only load a class that has not been previously loaded. Whether or not a class is already loaded is totally transparent to a Java application. It will be loaded as soon as it is referred to for the first time, be it instantiation or access to static members or a call to Class.forName().

  • How to load data dynamically into target tables using files as a source

    Hi ,
    My scenario needs a single interface to load the data of 5 different files into five target tables using a single interface. All target tables have the same structure. It is possible to point to variable source files using ODI. But the same approach is not working with Database tables. I am getting errors while trying to make my target /source table as a dynamic one.
    Can anybody suggest anything. The last option would be writing a dynamic PL/SQL block in the KM. Any other suggestions friends ?
    Regards,
    Atish

    After creating a pair of identical source and target tables, I have carried out the following steps:
    I am trying just keeping the target as variable
    a)created a one to one interface,
    b)tested that it is running.
    c)created a variable(type =text),
    d)used the variable as #v_name in the resource of the target table datastore.
    e)in a package used the variable in a set variable step (first step).
    f) used the interface as the second step.
    g)executed the same in my context.
    the <project_code>.variable_name is not getting substituted in the sql_code that is generated by the KM. My KM is SQL Control Append and following is the code that it generates in the Insert into I$ step:
    /* DETECTION_STRATEGY = NOT_EXISTS */
    insert /*+ APPEND */ into HR.I$_JOBS_COPY1
         JOB_ID,
         JOB_TITLE,
         MIN_SALARY,
         MAX_SALARY,
         IND_UPDATE
    select      
         JOBS.JOB_ID     JOB_ID,
         JOBS.JOB_TITLE     JOB_TITLE,
         JOBS.MIN_SALARY     MIN_SALARY,
         JOBS.MAX_SALARY     MAX_SALARY,
         'I' IND_UPDATE
    from     HR.JOBS JOBS
    where     (1=1)
    and not exists (
         select     'X'
         from     HR.#PLAYGROUND."v_tab_name" T
         where     T.JOB_ID     = JOBS.JOB_ID
              and     ((JOBS.JOB_TITLE = T.JOB_TITLE) or (JOBS.JOB_TITLE IS NULL and T.JOB_TITLE IS NULL))
              and     ((JOBS.MIN_SALARY = T.MIN_SALARY) or (JOBS.MIN_SALARY IS NULL and T.MIN_SALARY IS NULL))
              and     ((JOBS.MAX_SALARY = T.MAX_SALARY) or (JOBS.MAX_SALARY IS NULL and T.MAX_SALARY IS NULL))
         )

  • How to load classes for a particular package

    I have a package name say com.test
    i need to get the names of all the classes starting with "Test" under this package. Also, i need to get the names of all the methods starting with "test" in each of these classes.
    ideas/suggestions welcome :)
    cheers
    yogesh

    Kaj,
    thnx for ur time :)
    i am developing a testing framework for our web applications. all our applications wd require to have com.test as the package which will contain all the JUnit test classes. the package name (com.test) will be provided by the tester thru a properties file. my framework will load all the classes (and also fetch the method names starting with "test" in those classes) and display them on a gui in a html form. the tester will just select the junit test cases he wants to run and my framework will expose this service thru a servlet. the servlet will then invoke all the methods selected by the tester via reflection.
    if the way i want to do it is not possible cd u please suggest any alternatives ?
    cheers
    yogesh

  • How to load Classes?

    How to retrive the class name during runtime.....
    suppose if i select java.lang package , i must get all the classes relating to lang package....
    i used reflection API, but using that you can retrive constructor and methods of any class... and i need the classes of perticular package.... how to do it?
    Thank You

    Must it be in run-time? If no classloader tricks are applied, the whole class path contents could be perused to gain a list of the classes available there even berore running your application.

  • How to load data dynamically in as3 ?

    Hi,
    I'm working on a project. I want to add some interactivity after the completion of  each chapter in it. The scenario is this.
    1. One out of 10 questions should be asked randomly.
    2. 4 out of 10 pictures should be displayed randomly and one is the correct one.
    3. If User clicks on correct image, it should display some message as correct answer or some sound can be added.
    4. If user clicks on other 3 images, It should display some message as incorrect answer or some audio has to come.
    Need some suggestions.
    Thanks in advance.

    Hi,
    I sugest you one method , create one xml keep your images and question. Get the data from the xml and then  push in to one array, then you can randomize.
    To load the xml http://www.republicofcode.com/tutorials/flash/as3xml/ you can refer this
    to randomize http://script3.blogspot.in/2009/04/generating-random-numbers-with-out.html

  • How to load a Class Dynamically?

    hi,
    I have the following problem.I am trying to load a class dynamically.For this I am using ClassLoader and its Loadclass method.My code is like this,
    File file = filechooser.getSelectedFile();
    ClassLoader Cload = this.getClass().getClassLoader();
    String tempClsname= file.getName();
    Class cd =Cload.loadClass(tempClsname);
    Object ob =(Object)cd.newInstance();
    showMethods(ob);
    In showMethods what i am doing is getting the public methods of the dynamically loaded class,
    void showMethods(Object o){
    Class c = o.getClass();
    System.out.println(c.getName());
    vecList = new Vector();
    Method theMethods[] = c.getDeclaredMethods();
    for (int i = 0; i < theMethods.length; i++) {
    if(theMethods.getModifiers()==java.lang.reflect.Modifier.PUBLIC)
    String methodString = theMethods.getName();
    System.out.println(methodString);
    vecList.addElement(methodString);
    allmthdlst.setListData(vecList);
    Now whenever i work with this i m getting a runtime error of CLASS NOT FOUND Exception..I know its because of Classpath..But i don't know how to resolve it??pls help me in this regard...
    Also previously this code was working with java files in the directory in which this java file was present..How to make it work for java file in some other directory..pls help me in this regard...
    Thanks in advance..

    You sure didn't need to post this twice.
    http://forum.java.sun.com/thread.jsp?thread=522234&forum=31&message=2498659
    When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read and prevents accidental markup from array indices like [i].
    You resolve this problem by ensuring the class is in the classpath and you refer to it by its full name.
    &#167;

  • How to create an instance of a dynamically loaded class?

    Hi all,
    I am using ASM bytecode engineering framework to generate classes dynamically. I need to instantiate the classes dynamically as well. Request all to please enlighten me on the following points :
    (1) Presently I load the class using a custom class loader and then use Class.newInstance() method to obtain an instance. However, I read that reflection is slow. So is their a faster way to instantiate in this case?
    (2) The name of the classes are also generated automatically. And I don't know which class will actually be instantiated at runtime. So I have to store the refernce returned by Class.newInstance() in an Object type variable. And when I wish to invoke a method / access a data member on that instance, every time I need to cast the object to the appropriate class using Class.cast(). Can anyone please suggest a more efficient way to hold the reference?
    Thanks and Regards,
    Vinit_J

    Have those classes implement a particular interface, and hold the instances in references to that interface. If you're thinking "that's a bit restricting" then maybe you should re-think whether loading a class whose responsibilities are completely unknown at compile-time is as useful as you first thought it was

Maybe you are looking for