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.

Similar Messages

  • 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 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 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 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.

  • 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 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 a Jar file in the class path?

    How to load a Jar file which contains class files, images, etc.. in the classpath without using URLClassLoader.

    You don't "load" jars. If it's on the classpath, you can obtain individual resources from it using various methods on either Class or ClassLoader. Do you mean "how to add a jar to the classpath at runtime"? Can't be done without using a classloader, typically URLClassLoader or a subclass thereof. Why you want to not use the proven method is beyond me. Presumably because you don't understand classloading. In which case, forget it.

  • 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 Load a class manually

    Hello Friends,
    I need a help regarding how to load a class manually.
    i have the class name -- TestClass1
    and Path - com.apps.classes
    Thank you

    Thank You------
    I got the result
    String classPath = com.apps.className;
    Object obj = Class.forName(classPath).newInstance();

  • How to load java class from jsp page?

    hi all!
    Does anyone know how to load java class from jsp page?
    I try to load java class from jsp page.
    Is it possible to load java class fom jsp page?
    thanks and have a good day!

    What I mean is How to load/open java class file from jsp page?
    I think we can open Applet from jsp page by using
    <applet code=helloApplet.class width=100 height=100>
    </applet>
    but, how to open java class which is an application made by Frame?
    thanks and have a good day

  • How to load a class from a jar not in the classpath

    I have a gazillion jars of class files that I want to access dynamically in an application. I don't want to list every jar. The jars also contain images. With images you can explicitly point to the jar with and load the image with createImage....
    "jar:file:/C:/myjarlocation/myjar.jar!/pathtoimage/image.gif"
    Is there a similar string you can use when creating classes on the fly in a classloader with getClass().forName("classname") ??

    Hm, if you are not in an EJB container or some other environment that won't let you create a classloader, you might create a new URLClassLoader with a path pointing to those JARs. You will probably want to use your normal application class loader as the parent loader, so any referenced common class definitions are found during the load.
    Note that - in order to make use of the classes - you will normally need to know that they implement some interface (or inherit from a common base class) to which you can cast their instances. These Interfaces/base classes will have to be packaged for normal loading by your application class loader; else the cast will trigger an error during compile time. After this, loading them dynamically during runtime is no longer an option since they are referenced directly in the sourcecode.
    Alternatively you might do away with interfaces/base classes and call methods of dynamically loaded classes also dynamically: via reflection. But I guess this is too cumbersome for what you might have in mind. Also it has more invocation overhead, less type safety and handling all these exceptions wrapped in InvocationTargetExceptions can quickly become a nightmare too...

  • How can I control stage position for swfs loaded by Loader class?

    I'm creating a grid of buttons that, when clicked, will load a specific swf and I'd like for each swf to play in a certain portion of the stage.  When I use the Loader class:
    var my_loader:Loader = new Loader();
    my_loader.load(new URLRequest("abc.swf"));
    addChild(my_loader);
    the swf always displays at top left.  Is this an attribute of the individual swfs that I'm loading, or can I address the position in the main movie?
    Thanks-
    Sean

    addChild(my_loader);
    my_loader.x = 500;
    my_loader.y = 250;

Maybe you are looking for

  • WHY IS S.M.A.R.T STATUS SUPPORTED ON ATA BUS BUT NOT ON SCSI?

    I have 4 internal HD's on a G4 733 S-Drive (Digital Audio) running X.4.4 and my question is: Why is S.M.A.R.T STATUS supported on the ATA bus but not on the SCSI bus? Is there something wrong with my computer if only 2 of the 4 internal HD's read "Ve

  • Source Window play sound in sync with Timeline.

    When I originally opened the source of my Audio in Premier Pro CS5.5 the sound in the Source Window would play in sync with the Timeline. I clicked on the audio to try to zoom in closer - which I'm not sure how to do; any guidance appreciated as I'm

  • AE Errors - Memory

    Hi, I have been experiencing some seriously annoying AE problems. I'm experiencing these exact same issues on both: - iMac osx 10.9.4 3.2GHz Intel Core i5 processor - 8GB 1600 MHz DDR3 memory - Macbook Pro osx 10.9.4  2GHz Intel Core i& processor - 1

  • Safari & Mail Crashes

    I just reinstalled SL (10.6.2) and restored everything from my time machine due to some major issues I was having. Now Safari and Mail both crash within seconds of opening...everything else seems to work fine (I'm using Firefox to send this.) Any ide

  • I know my ipod mac adres but i can not find the serial no.p.s my ipod is not with me

    i know my ipods mac adres but i can not find the serial no since the ipod is not with me